1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Fix first-class callable in loop

This commit is contained in:
Aaron Piotrowski 2022-02-21 18:37:20 -06:00
parent 1a5b120081
commit 97b5685f55
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB
2 changed files with 40 additions and 4 deletions

View File

@ -77,11 +77,13 @@ class AssignmentMapVisitor extends PhpParser\NodeVisitorAbstract
|| $node instanceof PhpParser\Node\Expr\MethodCall || $node instanceof PhpParser\Node\Expr\MethodCall
|| $node instanceof PhpParser\Node\Expr\StaticCall || $node instanceof PhpParser\Node\Expr\StaticCall
) { ) {
foreach ($node->getArgs() as $arg) { if (!$node->isFirstClassCallable()) {
$arg_var_id = ExpressionIdentifier::getRootVarId($arg->value, $this->this_class_name); foreach ($node->getArgs() as $arg) {
$arg_var_id = ExpressionIdentifier::getRootVarId($arg->value, $this->this_class_name);
if ($arg_var_id) { if ($arg_var_id) {
$this->assignment_map[$arg_var_id][$arg_var_id] = true; $this->assignment_map[$arg_var_id][$arg_var_id] = true;
}
} }
} }

View File

@ -773,6 +773,40 @@ class ClosureTest extends TestCase
[], [],
'8.1', '8.1',
], ],
'FirstClassCallable:AssignmentVisitorMap' => [
'<?php
class Test {
/** @var list<\Closure():void> */
public array $handlers = [];
public function register(): void {
foreach ([1, 2, 3] as $index) {
$this->push($this->handler(...));
}
}
/**
* @param Closure():void $closure
* @return void
*/
private function push(\Closure $closure): void {
$this->handlers[] = $closure;
}
private function handler(): void {
}
}
$test = new Test();
$test->register();
$handlers = $test->handlers;
',
'assertions' => [
'$handlers' => 'list<Closure():void>',
],
'ignored_issues' => [],
'php_version' => '8.1',
],
'arrowFunctionReturnsNeverImplictly' => [ 'arrowFunctionReturnsNeverImplictly' => [
'<?php '<?php
$bar = ["foo", "bar"]; $bar = ["foo", "bar"];