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:
parent
72104a52ad
commit
63b35fc889
@ -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()
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -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;
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user