1
0
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:
adrew 2021-12-05 15:33:18 +03:00
parent eb4e9dee86
commit bc61547bce
2 changed files with 21 additions and 0 deletions

View File

@ -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 [];
}
}

View File

@ -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"}>',
]
],
];
}