Skip to content

Commit 219e791

Browse files
phpstan-botclaude
andcommitted
Clarify comments: two-pass matching is about preferring exact matches, not speed
Move the explanation of why Pass 1 takes priority from Pass 2's comment block to Pass 1's comment, making it clear that the two-pass design is about preferring exact matches over supertype matches to avoid certainty degradation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent aa1f96e commit 219e791

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

src/Analyser/MutatingScope.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3218,7 +3218,10 @@ public function filterBySpecifiedTypes(SpecifiedTypes $specifiedTypes): self
32183218
}
32193219

32203220
// Pass 1: Exact match - condition type must equal the specified expression type.
3221-
// This handles most cases and takes priority over Pass 2.
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.
32223225
foreach ($conditionalExpressions as $conditionalExpression) {
32233226
foreach ($conditionalExpression->getConditionExpressionTypeHolders() as $holderExprString => $conditionalTypeHolder) {
32243227
if (
@@ -3248,11 +3251,6 @@ public function filterBySpecifiedTypes(SpecifiedTypes $specifiedTypes): self
32483251
// Also needed for scope merging: e.g. $a=0 then if (is_string||is_int) $a=1
32493252
// creates a condition type int|string. When narrowed to is_int, the condition
32503253
// int|string is a supertype of int, so the match succeeds.
3251-
//
3252-
// Pass 1 must take priority because when both exact and broader conditions exist
3253-
// (e.g. from scope merging creating both "$key=2 => $value Yes" and
3254-
// "$key=0|2 => $value Maybe"), the broader match would degrade certainty
3255-
// via extremeIdentity (Yes AND Maybe = Maybe), causing false positives.
32563254
foreach ($conditionalExpressions as $conditionalExpression) {
32573255
foreach ($conditionalExpression->getConditionExpressionTypeHolders() as $holderExprString => $conditionalTypeHolder) {
32583256
if (

0 commit comments

Comments
 (0)