Commit 44a1089
Fix phpstan/phpstan#6830: Variable inside loop might not be defined
- Modified intersectConditionalExpressions() in MutatingScope to match
conditional expressions by their condition part when exact key match
fails, then merge result type holders via and()
- Added conditionExpressionTypeHoldersEqual() helper method
- New regression test in tests/PHPStan/Rules/Variables/data/bug-6830b.php
- Root cause: conditional expression keys include result types, which
change across loop iterations when variables are reassigned, causing
the intersection to drop them entirely1 parent 9e4186e commit 44a1089
File tree
3 files changed
+73
-3
lines changed- src/Analyser
- tests/PHPStan/Rules/Variables
- data
3 files changed
+73
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3432 | 3432 | | |
3433 | 3433 | | |
3434 | 3434 | | |
3435 | | - | |
3436 | | - | |
| 3435 | + | |
| 3436 | + | |
| 3437 | + | |
| 3438 | + | |
3437 | 3439 | | |
3438 | 3440 | | |
3439 | | - | |
| 3441 | + | |
| 3442 | + | |
| 3443 | + | |
| 3444 | + | |
| 3445 | + | |
| 3446 | + | |
| 3447 | + | |
| 3448 | + | |
| 3449 | + | |
| 3450 | + | |
| 3451 | + | |
| 3452 | + | |
| 3453 | + | |
| 3454 | + | |
| 3455 | + | |
| 3456 | + | |
| 3457 | + | |
3440 | 3458 | | |
3441 | 3459 | | |
3442 | 3460 | | |
| |||
3449 | 3467 | | |
3450 | 3468 | | |
3451 | 3469 | | |
| 3470 | + | |
| 3471 | + | |
| 3472 | + | |
| 3473 | + | |
| 3474 | + | |
| 3475 | + | |
| 3476 | + | |
| 3477 | + | |
| 3478 | + | |
| 3479 | + | |
| 3480 | + | |
| 3481 | + | |
| 3482 | + | |
| 3483 | + | |
| 3484 | + | |
| 3485 | + | |
| 3486 | + | |
| 3487 | + | |
| 3488 | + | |
| 3489 | + | |
| 3490 | + | |
| 3491 | + | |
3452 | 3492 | | |
3453 | 3493 | | |
3454 | 3494 | | |
| |||
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1393 | 1393 | | |
1394 | 1394 | | |
1395 | 1395 | | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
1396 | 1406 | | |
1397 | 1407 | | |
1398 | 1408 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
0 commit comments