1
0
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:
orklah 2021-12-05 16:25:21 +01:00 committed by GitHub
commit f67a0ca143
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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"}>',
]
],
];
}