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:
parent
1a5b120081
commit
97b5685f55
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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"];
|
||||||
|
Loading…
Reference in New Issue
Block a user