Skip to content

Commit aec0406

Browse files
committed
Do not create conditional expression for the same variable
1 parent 8234dc0 commit aec0406

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/Analyser/TypeSpecifier.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1209,8 +1209,28 @@ private function processBooleanConditionalTypes(Scope $scope, SpecifiedTypes $le
12091209
$holders[$exprString] = [];
12101210
}
12111211

1212+
$conditions = $conditionExpressionTypes;
1213+
foreach ($conditions as $conditionExprString => $conditionExprTypeHolder) {
1214+
$conditionExpr = $conditionExprTypeHolder->getExpr();
1215+
if (!$conditionExpr instanceof Expr\Variable) {
1216+
continue;
1217+
}
1218+
if (!is_string($conditionExpr->name)) {
1219+
continue;
1220+
}
1221+
if ($conditionExpr->name !== $expr->name) {
1222+
continue;
1223+
}
1224+
1225+
unset($conditions[$conditionExprString]);
1226+
}
1227+
1228+
if (count($conditions) === 0) {
1229+
continue;
1230+
}
1231+
12121232
$holder = new ConditionalExpressionHolder(
1213-
$conditionExpressionTypes,
1233+
$conditions,
12141234
new ExpressionTypeHolder($expr, TypeCombinator::remove($scope->getType($expr), $type), TrinaryLogic::createYes()),
12151235
);
12161236
$holders[$exprString][$holder->getKey()] = $holder;

0 commit comments

Comments
 (0)