Skip to content

Commit 3e20db3

Browse files
rajyanondrejmirtes
authored andcommitted
take over variable related types when entering function scopes
1 parent 123ae4e commit 3e20db3

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/Analyser/MutatingScope.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,6 +2360,7 @@ public function isSpecified(Expr $node): bool
23602360
{
23612361
$exprString = $this->getNodeKey($node);
23622362

2363+
// TODO
23632364
return !$node instanceof Variable && isset($this->variableTypes[$exprString])
23642365
&& $this->variableTypes[$exprString]->getCertainty()->yes();
23652366
}
@@ -2889,6 +2890,27 @@ private function enterAnonymousFunctionWithoutReflection(
28892890
$nativeTypes[$paramExprString] = $this->getNativeType($use->var);
28902891
}
28912892
$variableTypes[$paramExprString] = VariableTypeHolder::createYes($variableType);
2893+
2894+
foreach ($this->variableTypes as $exprString => $typeHolder) {
2895+
$expr = $this->exprStringToExpr((string) $exprString);
2896+
if ($expr === null) {
2897+
continue;
2898+
}
2899+
if ($expr instanceof Variable) {
2900+
continue;
2901+
}
2902+
$variable = (new NodeFinder())->findFirst([$expr], static fn (Node $node): bool => $node instanceof Variable);
2903+
if (!$variable instanceof Variable) {
2904+
continue;
2905+
}
2906+
if (!is_string($variable->name)) {
2907+
continue;
2908+
}
2909+
if ($variable->name !== $variableName) {
2910+
continue;
2911+
}
2912+
$variableTypes[$exprString] = $typeHolder;
2913+
}
28922914
}
28932915

28942916
if ($this->hasVariableType('this')->yes() && !$closure->static) {

0 commit comments

Comments
 (0)