1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix #3058 - use value for generator inference

This commit is contained in:
Brown 2020-04-02 20:37:09 -04:00
parent 72104a52ad
commit 63b35fc889
2 changed files with 17 additions and 2 deletions

View File

@ -322,12 +322,16 @@ class ReturnTypeCollector
$key_type = $stmt_key_type;
}
if ($stmt_type = $nodes->getType($stmt)) {
if ($stmt->value
&& $value_type = $nodes->getType($stmt->value)
) {
$generator_type = new Atomic\TGenericObject(
'Generator',
[
$key_type ?: Type::getInt(),
$stmt_type,
clone $value_type,
Type::getMixed(),
Type::getMixed()
]
);

View File

@ -787,6 +787,17 @@ class ReturnTypeTest extends TestCase
'$res' => 'iterable<mixed, string>',
],
],
'yieldWithReturn' => [
'<?php
/** @return Generator<int, string, int, int> */
function gen(): Generator {
yield 3 => "abc";
$foo = 4;
return $foo;
}'
],
];
}