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

Add descendant variables for closure uses

Fixes #4522
This commit is contained in:
Matt Brown 2020-11-09 15:20:28 -05:00
parent e97a9c86eb
commit 32d526bde9
2 changed files with 22 additions and 0 deletions

View File

@ -160,6 +160,13 @@ class ClosureAnalyzer extends FunctionLikeAnalyzer
: Type::getMixed();
$use_context->vars_possibly_in_scope[$use_var_id] = true;
foreach ($context->vars_in_scope as $var_id => $type) {
if (preg_match('/^\$' . $use->var->name . '[\[\-]/', $var_id)) {
$use_context->vars_in_scope[$var_id] = clone $type;
$use_context->vars_possibly_in_scope[$var_id] = true;
}
}
}
} else {
$traverser = new PhpParser\NodeTraverser;

View File

@ -519,6 +519,21 @@ class ClosureTest extends TestCase
[],
'7.4'
],
'rememberParentAssertions' => [
'<?php
class A {
public ?A $a = null;
public function foo() : void {}
}
function doFoo(A $a): void {
if ($a->a instanceof A) {
function () use ($a): void {
$a->a->foo();
};
}
}'
],
];
}