Skip to content

Commit ffd567d

Browse files
committed
Update MutatingScope.php
1 parent 219e791 commit ffd567d

1 file changed

Lines changed: 2 additions & 16 deletions

File tree

src/Analyser/MutatingScope.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3217,11 +3217,7 @@ public function filterBySpecifiedTypes(SpecifiedTypes $specifiedTypes): self
32173217
continue;
32183218
}
32193219

3220-
// Pass 1: Exact match - condition type must equal the specified expression type.
3221-
// We prefer exact matches over supertype matches (Pass 2) because when both
3222-
// exist (e.g. from scope merging creating both "$key=2 => $value Yes" and
3223-
// "$key=0|2 => $value Maybe"), the broader match would degrade certainty
3224-
// via extremeIdentity (Yes AND Maybe = Maybe), causing false positives.
3220+
// Pass 1: Prefer exact matches
32253221
foreach ($conditionalExpressions as $conditionalExpression) {
32263222
foreach ($conditionalExpression->getConditionExpressionTypeHolders() as $holderExprString => $conditionalTypeHolder) {
32273223
if (
@@ -3240,17 +3236,7 @@ public function filterBySpecifiedTypes(SpecifiedTypes $specifiedTypes): self
32403236
continue;
32413237
}
32423238

3243-
// Pass 2: Supertype match - condition type must be a supertype of the specified
3244-
// expression type. Only runs when Pass 1 found no exact match for this expression.
3245-
//
3246-
// This is needed for conditional parameter types with union conditions:
3247-
// e.g. @param ($p is 'a' ? bool : int) with $p typed as 'a'|'b'|'c'
3248-
// creates a condition type 'b'|'c' (from TypeCombinator::remove) for the int result.
3249-
// When $p is narrowed to 'b', equals('b', 'b'|'c') fails but isSuperTypeOf succeeds.
3250-
//
3251-
// Also needed for scope merging: e.g. $a=0 then if (is_string||is_int) $a=1
3252-
// creates a condition type int|string. When narrowed to is_int, the condition
3253-
// int|string is a supertype of int, so the match succeeds.
3239+
// Pass 2: Supertype match. Only runs when Pass 1 found no exact match for this expression.
32543240
foreach ($conditionalExpressions as $conditionalExpression) {
32553241
foreach ($conditionalExpression->getConditionExpressionTypeHolders() as $holderExprString => $conditionalTypeHolder) {
32563242
if (

0 commit comments

Comments
 (0)