Skip to content

Commit

Permalink
Merge pull request #7715 from trowski/fix-ffc-in-loop
Browse files Browse the repository at this point in the history
Fix first-class callable in loop
  • Loading branch information
orklah committed Feb 22, 2022
2 parents 1a5b120 + 97b5685 commit d2493e2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Psalm/Internal/PhpVisitor/AssignmentMapVisitor.php
Expand Up @@ -77,11 +77,13 @@ public function enterNode(PhpParser\Node $node): ?int
|| $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;
}
}
}

Expand Down
34 changes: 34 additions & 0 deletions tests/ClosureTest.php
Expand Up @@ -773,6 +773,40 @@ public static function __callStatic(string $name, array $args): mixed {
[],
'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"];
Expand Down

0 comments on commit d2493e2

Please sign in to comment.