mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Merge pull request #7715 from trowski/fix-ffc-in-loop
Fix first-class callable in loop
This commit is contained in:
commit
d2493e2656
@ -77,11 +77,13 @@ class AssignmentMapVisitor extends PhpParser\NodeVisitorAbstract
|
||||
|| $node instanceof PhpParser\Node\Expr\MethodCall
|
||||
|| $node instanceof PhpParser\Node\Expr\StaticCall
|
||||
) {
|
||||
foreach ($node->getArgs() as $arg) {
|
||||
$arg_var_id = ExpressionIdentifier::getRootVarId($arg->value, $this->this_class_name);
|
||||
if (!$node->isFirstClassCallable()) {
|
||||
foreach ($node->getArgs() as $arg) {
|
||||
$arg_var_id = ExpressionIdentifier::getRootVarId($arg->value, $this->this_class_name);
|
||||
|
||||
if ($arg_var_id) {
|
||||
$this->assignment_map[$arg_var_id][$arg_var_id] = true;
|
||||
if ($arg_var_id) {
|
||||
$this->assignment_map[$arg_var_id][$arg_var_id] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -773,6 +773,40 @@ class ClosureTest extends TestCase
|
||||
[],
|
||||
'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' => [
|
||||
'<?php
|
||||
$bar = ["foo", "bar"];
|
||||
|
Loading…
Reference in New Issue
Block a user