mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
detect yield in array expression
This commit is contained in:
parent
eb4e9dee86
commit
bc61547bce
@ -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