Commit 21b91c0
Remove useSubtypeForConditionMatching flag, use two-pass matching instead
Instead of a flag on ConditionalExpressionHolder to control whether
condition matching uses equals() or isSuperTypeOf(), use a two-pass
approach in filterBySpecifiedTypes():
Pass 1: exact matching via equals() (existing behavior)
Pass 2: isSuperTypeOf for condition types with finite types (fallback)
Pass 2 only runs when pass 1 found no matches for a target expression.
This handles conditional parameter types where the condition is a union
(e.g. 'value1'|'value2') that can't match a narrowed type ('value1')
via equals(), but should match via isSuperTypeOf.
The two-pass approach avoids regressions from using isSuperTypeOf
globally: when scope merging creates both a specific condition (e.g.
"if $key=2, then $value is Yes") and a broader condition (e.g. "if
$key=0|2, then $value is Maybe"), exact matching in pass 1 prevents
the broader condition from degrading variable certainty through
extremeIdentity.
The bug-5051 test expectations are updated to reflect more precise
type narrowing: when narrowing $data to a specific constant, PHPStan
now correctly determines which branch was taken and narrows related
variables accordingly (e.g. $update becomes 'false' instead of 'bool'
when $data === 1 because that branch always sets $update = false).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1 parent 151b7b8 commit 21b91c0
File tree
3 files changed
+39
-27
lines changed- src/Analyser
- tests/PHPStan/Analyser/nsrt
3 files changed
+39
-27
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
| |||
38 | 37 | | |
39 | 38 | | |
40 | 39 | | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | 40 | | |
47 | 41 | | |
48 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1760 | 1760 | | |
1761 | 1761 | | |
1762 | 1762 | | |
1763 | | - | |
| 1763 | + | |
1764 | 1764 | | |
1765 | 1765 | | |
1766 | 1766 | | |
1767 | 1767 | | |
1768 | | - | |
| 1768 | + | |
1769 | 1769 | | |
1770 | 1770 | | |
1771 | 1771 | | |
| |||
3216 | 3216 | | |
3217 | 3217 | | |
3218 | 3218 | | |
| 3219 | + | |
| 3220 | + | |
3219 | 3221 | | |
3220 | 3222 | | |
3221 | | - | |
3222 | | - | |
3223 | | - | |
3224 | | - | |
3225 | | - | |
| 3223 | + | |
3226 | 3224 | | |
3227 | 3225 | | |
3228 | | - | |
3229 | | - | |
| 3226 | + | |
| 3227 | + | |
| 3228 | + | |
| 3229 | + | |
| 3230 | + | |
| 3231 | + | |
| 3232 | + | |
| 3233 | + | |
| 3234 | + | |
| 3235 | + | |
| 3236 | + | |
| 3237 | + | |
| 3238 | + | |
| 3239 | + | |
| 3240 | + | |
| 3241 | + | |
3230 | 3242 | | |
3231 | 3243 | | |
3232 | | - | |
3233 | | - | |
| 3244 | + | |
| 3245 | + | |
| 3246 | + | |
| 3247 | + | |
| 3248 | + | |
| 3249 | + | |
| 3250 | + | |
| 3251 | + | |
3234 | 3252 | | |
3235 | 3253 | | |
3236 | 3254 | | |
3237 | | - | |
3238 | 3255 | | |
3239 | | - | |
3240 | | - | |
| 3256 | + | |
| 3257 | + | |
| 3258 | + | |
3241 | 3259 | | |
3242 | 3260 | | |
3243 | 3261 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
68 | | - | |
| 67 | + | |
| 68 | + | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
76 | | - | |
| 75 | + | |
| 76 | + | |
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
| 83 | + | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| |||
0 commit comments