Commit 9698573
Only preserve vacuous conditional expressions during if/else branch merging
The preserveVacuousConditionalExpressions logic was being applied to all
mergeWith calls, including loop merging. In loop contexts, this incorrectly
preserved per-iteration branch correlations (e.g., "if $operators is
array{Operator}, then $operands is array{}") across iterations, causing
types to be over-narrowed (int → 0, non-empty-list<int> → array{int}).
Fix: add a $preserveVacuousConditionals parameter to mergeWith() (default
false) and only pass true from the if/elseif/else branch merge sites in
NodeScopeResolver.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1 parent d62fe52 commit 9698573
3 files changed
Lines changed: 19 additions & 17 deletions
File tree
- src/Analyser
- tests/PHPStan/Analyser/nsrt
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3362 | 3362 | | |
3363 | 3363 | | |
3364 | 3364 | | |
3365 | | - | |
| 3365 | + | |
3366 | 3366 | | |
3367 | 3367 | | |
3368 | 3368 | | |
| |||
3372 | 3372 | | |
3373 | 3373 | | |
3374 | 3374 | | |
3375 | | - | |
3376 | | - | |
3377 | | - | |
3378 | | - | |
3379 | | - | |
3380 | | - | |
3381 | | - | |
3382 | | - | |
3383 | | - | |
3384 | | - | |
| 3375 | + | |
| 3376 | + | |
| 3377 | + | |
| 3378 | + | |
| 3379 | + | |
| 3380 | + | |
| 3381 | + | |
| 3382 | + | |
| 3383 | + | |
| 3384 | + | |
| 3385 | + | |
| 3386 | + | |
3385 | 3387 | | |
3386 | 3388 | | |
3387 | 3389 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1146 | 1146 | | |
1147 | 1147 | | |
1148 | 1148 | | |
1149 | | - | |
| 1149 | + | |
1150 | 1150 | | |
1151 | 1151 | | |
1152 | 1152 | | |
| |||
1170 | 1170 | | |
1171 | 1171 | | |
1172 | 1172 | | |
1173 | | - | |
| 1173 | + | |
1174 | 1174 | | |
1175 | 1175 | | |
1176 | 1176 | | |
| |||
1182 | 1182 | | |
1183 | 1183 | | |
1184 | 1184 | | |
1185 | | - | |
| 1185 | + | |
1186 | 1186 | | |
1187 | 1187 | | |
1188 | 1188 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | | - | |
| 34 | + | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
0 commit comments