Skip to content

Commit

Permalink
Fix conditional bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Nov 28, 2023
1 parent e5580c5 commit a76b82d
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/Analyser/TypeSpecifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -1315,8 +1315,28 @@ private function processBooleanSureConditionalTypes(Scope $scope, SpecifiedTypes
$holders[$exprString] = [];
}

$conditions = $conditionExpressionTypes;
foreach ($conditions as $conditionExprString => $conditionExprTypeHolder) {
$conditionExpr = $conditionExprTypeHolder->getExpr();
if (!$conditionExpr instanceof Expr\Variable) {
continue;
}
if (!is_string($conditionExpr->name)) {
continue;
}
if ($conditionExpr->name !== $expr->name) {
continue;
}

unset($conditions[$conditionExprString]);
}

if (count($conditions) === 0) {
continue;
}

$holder = new ConditionalExpressionHolder(
$conditionExpressionTypes,
$conditions,
new ExpressionTypeHolder($expr, TypeCombinator::intersect($scope->getType($expr), $type), TrinaryLogic::createYes()),
);
$holders[$exprString][$holder->getKey()] = $holder;
Expand Down

0 comments on commit a76b82d

Please sign in to comment.