diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index ead7b24c5c..6574d0a1c8 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -945,7 +945,7 @@ private function resolveType(string $exprString, Expr $node): Type !$node instanceof Variable && !$node instanceof Expr\Closure && !$node instanceof Expr\ArrowFunction - && $this->hasExpressionType($node)->yes() + && $this->hasExpressionTypeByString($exprString, $node)->yes() ) { return $this->expressionTypes[$exprString]->getType(); } @@ -2074,10 +2074,11 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu continue; } $constFetch = new ConstFetch($name); - if ($this->hasExpressionType($constFetch)->yes()) { + $constExprString = $this->getNodeKey($constFetch); + if ($this->hasExpressionTypeByString($constExprString, $constFetch)->yes()) { return $this->constantResolver->resolveConstantType( $name->toString(), - $this->expressionTypes[$this->getNodeKey($constFetch)]->getType(), + $this->expressionTypes[$constExprString]->getType(), ); } } @@ -2089,7 +2090,7 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu return new ErrorType(); } elseif ($node instanceof Node\Expr\ClassConstFetch && $node->name instanceof Node\Identifier) { - if ($this->hasExpressionType($node)->yes()) { + if ($this->hasExpressionTypeByString($exprString, $node)->yes()) { return $this->expressionTypes[$exprString]->getType(); } return $this->initializerExprTypeResolver->getClassConstFetchTypeByReflection( @@ -2924,7 +2925,18 @@ public function hasExpressionType(Expr $node): TrinaryLogic return $this->hasVariableType($node->name); } - $exprString = $this->getNodeKey($node); + return $this->hasExpressionTypeByString( + $this->getNodeKey($node), + $node, + ); + } + + private function hasExpressionTypeByString(string $exprString, Expr $node): TrinaryLogic + { + if ($node instanceof Variable) { + throw new ShouldNotHappenException(); + } + if (!isset($this->expressionTypes[$exprString])) { return TrinaryLogic::createNo(); }