From 98241ddc3665f806147795c3db81f85486ae9bbd Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 13 Dec 2022 15:19:19 +0100 Subject: [PATCH] Prevent overly greedy $scope->getType() calls in NodeScopeResolver --- src/Analyser/NodeScopeResolver.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Analyser/NodeScopeResolver.php b/src/Analyser/NodeScopeResolver.php index 0c399c30ec..5e07bd96df 100644 --- a/src/Analyser/NodeScopeResolver.php +++ b/src/Analyser/NodeScopeResolver.php @@ -1622,8 +1622,9 @@ private function ensureShallowNonNullability(MutatingScope $scope, Scope $origin $exprTypeWithoutNull = TypeCombinator::removeNull($exprType); if ($exprType->equals($exprTypeWithoutNull)) { $originalExprType = $originalScope->getType($exprToSpecify); - $originalNativeType = $originalScope->getNativeType($exprToSpecify); if (!$originalExprType->equals($exprTypeWithoutNull)) { + $originalNativeType = $originalScope->getNativeType($exprToSpecify); + return new EnsuredNonNullabilityResult($scope, [ new EnsuredNonNullabilityResultExpression($exprToSpecify, $originalExprType, $originalNativeType), ]); @@ -2643,14 +2644,17 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void { $elseResult = $this->processExprNode($expr->else, $ifFalseScope, $nodeCallback, $context); $throwPoints = array_merge($throwPoints, $elseResult->getThrowPoints()); $ifFalseScope = $elseResult->getScope(); - $ifFalseType = $ifFalseScope->getType($expr->else); if ($ifTrueType instanceof NeverType && $ifTrueType->isExplicit()) { $finalScope = $ifFalseScope; - } elseif ($ifFalseType instanceof NeverType && $ifFalseType->isExplicit()) { - $finalScope = $ifTrueScope; } else { - $finalScope = $ifTrueScope->mergeWith($ifFalseScope); + $ifFalseType = $ifFalseScope->getType($expr->else); + + if ($ifFalseType instanceof NeverType && $ifFalseType->isExplicit()) { + $finalScope = $ifTrueScope; + } else { + $finalScope = $ifTrueScope->mergeWith($ifFalseScope); + } } return new ExpressionResult(