Skip to content

Commit

Permalink
Prevent overly greedy $scope->getType() calls in NodeScopeResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored and ondrejmirtes committed Dec 13, 2022
1 parent 3a70b59 commit 0962e97
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Analyser/NodeScopeResolver.php
Expand Up @@ -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),
]);
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 0962e97

Please sign in to comment.