Skip to content

Commit 72f2b6e

Browse files
phpstan-botclaude
andcommitted
Skip trivially-always-true conditions in processBooleanNotSureConditionalTypes
Apply the same fix from processBooleanSureConditionalTypes to its symmetric counterpart. When TypeCombinator::intersect(scopeType, type) returns the scope type unchanged, the condition is trivially always true and should be skipped to avoid creating spurious conditional expression holders. The other TypeCombinator::remove calls (in AssignHandler and on the result side of processBooleanNotSureConditionalTypes) cannot be fixed the same way because their holders carry createYes certainty that matters for conditionally-defined variables — even when the type itself doesn't change. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 909a316 commit 72f2b6e

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/Analyser/TypeSpecifier.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2066,9 +2066,15 @@ private function processBooleanNotSureConditionalTypes(Scope $scope, SpecifiedTy
20662066
continue;
20672067
}
20682068

2069+
$scopeType = $scope->getType($expr);
2070+
$conditionType = TypeCombinator::intersect($scopeType, $type);
2071+
if ($scopeType->equals($conditionType)) {
2072+
continue;
2073+
}
2074+
20692075
$conditionExpressionTypes[$exprString] = ExpressionTypeHolder::createYes(
20702076
$expr,
2071-
TypeCombinator::intersect($scope->getType($expr), $type),
2077+
$conditionType,
20722078
);
20732079
}
20742080

0 commit comments

Comments
 (0)