mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Merge pull request #7068 from klimick/fix-yield
Detect yield in array expression
This commit is contained in:
commit
f67a0ca143
@ -355,6 +355,18 @@ class ReturnTypeCollector
|
||||
return $yield_types;
|
||||
}
|
||||
|
||||
if ($stmt instanceof PhpParser\Node\Expr\Array_) {
|
||||
$yield_types = [];
|
||||
|
||||
foreach ($stmt->items as $item) {
|
||||
if ($item instanceof PhpParser\Node\Expr\ArrayItem) {
|
||||
$yield_types = array_merge($yield_types, self::getYieldTypeFromExpression($item->value, $nodes));
|
||||
}
|
||||
}
|
||||
|
||||
return $yield_types;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
@ -298,6 +298,15 @@ class GeneratorTest extends TestCase
|
||||
'$_a' => 'pure-Closure():Generator<int, "a", mixed, RuntimeException>',
|
||||
]
|
||||
],
|
||||
'detectYieldInArray' => [
|
||||
'<?php
|
||||
/** @psalm-suppress MissingClosureReturnType */
|
||||
$_a = function() { return [yield "a"]; };
|
||||
',
|
||||
'assertions' => [
|
||||
'$_a' => 'pure-Closure():Generator<int, "a", mixed, array{"a"}>',
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user