Skip to content

Commit 8dcd2ae

Browse files
staabmondrejmirtes
authored andcommitted
Prevent unnecessary work when resolving Expr\BinaryOp\Coalesce
1 parent cf48d9b commit 8dcd2ae

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/Analyser/MutatingScope.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,7 +2012,6 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
20122012

20132013
if ($node instanceof Expr\BinaryOp\Coalesce) {
20142014
$issetLeftExpr = new Expr\Isset_([$node->left]);
2015-
$leftType = $this->filterByTruthyValue($issetLeftExpr)->getType($node->left);
20162015

20172016
$result = $this->issetCheck($node->left, static function (Type $type): ?bool {
20182017
$isNull = $type->isNull();
@@ -2024,14 +2023,14 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
20242023
});
20252024

20262025
if ($result !== null && $result !== false) {
2027-
return TypeCombinator::removeNull($leftType);
2026+
return TypeCombinator::removeNull($this->filterByTruthyValue($issetLeftExpr)->getType($node->left));
20282027
}
20292028

20302029
$rightType = $this->filterByFalseyValue($issetLeftExpr)->getType($node->right);
20312030

20322031
if ($result === null) {
20332032
return TypeCombinator::union(
2034-
TypeCombinator::removeNull($leftType),
2033+
TypeCombinator::removeNull($this->filterByTruthyValue($issetLeftExpr)->getType($node->left)),
20352034
$rightType,
20362035
);
20372036
}

0 commit comments

Comments
 (0)