Skip to content

Commit 0962e97

Browse files
staabmondrejmirtes
authored andcommitted
Prevent overly greedy $scope->getType() calls in NodeScopeResolver
1 parent 3a70b59 commit 0962e97

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,8 +1622,9 @@ private function ensureShallowNonNullability(MutatingScope $scope, Scope $origin
16221622
$exprTypeWithoutNull = TypeCombinator::removeNull($exprType);
16231623
if ($exprType->equals($exprTypeWithoutNull)) {
16241624
$originalExprType = $originalScope->getType($exprToSpecify);
1625-
$originalNativeType = $originalScope->getNativeType($exprToSpecify);
16261625
if (!$originalExprType->equals($exprTypeWithoutNull)) {
1626+
$originalNativeType = $originalScope->getNativeType($exprToSpecify);
1627+
16271628
return new EnsuredNonNullabilityResult($scope, [
16281629
new EnsuredNonNullabilityResultExpression($exprToSpecify, $originalExprType, $originalNativeType),
16291630
]);
@@ -2643,14 +2644,17 @@ static function (Node $node, Scope $scope) use ($nodeCallback): void {
26432644
$elseResult = $this->processExprNode($expr->else, $ifFalseScope, $nodeCallback, $context);
26442645
$throwPoints = array_merge($throwPoints, $elseResult->getThrowPoints());
26452646
$ifFalseScope = $elseResult->getScope();
2646-
$ifFalseType = $ifFalseScope->getType($expr->else);
26472647

26482648
if ($ifTrueType instanceof NeverType && $ifTrueType->isExplicit()) {
26492649
$finalScope = $ifFalseScope;
2650-
} elseif ($ifFalseType instanceof NeverType && $ifFalseType->isExplicit()) {
2651-
$finalScope = $ifTrueScope;
26522650
} else {
2653-
$finalScope = $ifTrueScope->mergeWith($ifFalseScope);
2651+
$ifFalseType = $ifFalseScope->getType($expr->else);
2652+
2653+
if ($ifFalseType instanceof NeverType && $ifFalseType->isExplicit()) {
2654+
$finalScope = $ifTrueScope;
2655+
} else {
2656+
$finalScope = $ifTrueScope->mergeWith($ifFalseScope);
2657+
}
26542658
}
26552659

26562660
return new ExpressionResult(

0 commit comments

Comments
 (0)