Commit d445074
Fix spurious nullCoalesce.offset error after nested ?? with nullable types
- Fixed false positive where `$x[0] ?? null` was flagged as unnecessary after
`$x[0]['bar'] ?? null` when the inner type was nullable (e.g. list<array<?string>>)
- Root cause: revertNonNullability used specifyExpressionType which recursively
creates expression type holders for parent arrays as side effects, leaving
spurious Yes-certainty expression types for intermediate array dim fetches
- Added sideEffectSave flag to EnsuredNonNullabilityResultExpression to distinguish
target saves (null actually removed) from side-effect saves (type changed by
recursive parent narrowing)
- After reverting, unset expression types for side-effect saves that didn't exist
in the original scope
- Added unsetExpressionType method to MutatingScope
- New regression test in tests/PHPStan/Rules/Variables/data/bug-13921.php
Closes phpstan/phpstan#139211 parent 1b3396d commit d445074
File tree
5 files changed
+73
-4
lines changed- src/Analyser
- tests/PHPStan/Rules/Variables
- data
5 files changed
+73
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| |||
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
41 | 53 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3547 | 3547 | | |
3548 | 3548 | | |
3549 | 3549 | | |
| 3550 | + | |
| 3551 | + | |
| 3552 | + | |
| 3553 | + | |
| 3554 | + | |
| 3555 | + | |
| 3556 | + | |
| 3557 | + | |
| 3558 | + | |
| 3559 | + | |
| 3560 | + | |
| 3561 | + | |
| 3562 | + | |
| 3563 | + | |
| 3564 | + | |
| 3565 | + | |
| 3566 | + | |
| 3567 | + | |
| 3568 | + | |
| 3569 | + | |
| 3570 | + | |
| 3571 | + | |
| 3572 | + | |
| 3573 | + | |
| 3574 | + | |
| 3575 | + | |
| 3576 | + | |
| 3577 | + | |
3550 | 3578 | | |
3551 | 3579 | | |
3552 | 3580 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2473 | 2473 | | |
2474 | 2474 | | |
2475 | 2475 | | |
2476 | | - | |
| 2476 | + | |
| 2477 | + | |
2477 | 2478 | | |
2478 | 2479 | | |
2479 | 2480 | | |
| |||
2484 | 2485 | | |
2485 | 2486 | | |
2486 | 2487 | | |
2487 | | - | |
| 2488 | + | |
2488 | 2489 | | |
2489 | 2490 | | |
2490 | 2491 | | |
| |||
2493 | 2494 | | |
2494 | 2495 | | |
2495 | 2496 | | |
2496 | | - | |
| 2497 | + | |
2497 | 2498 | | |
2498 | 2499 | | |
2499 | 2500 | | |
| |||
2503 | 2504 | | |
2504 | 2505 | | |
2505 | 2506 | | |
2506 | | - | |
| 2507 | + | |
| 2508 | + | |
2507 | 2509 | | |
2508 | 2510 | | |
2509 | 2511 | | |
2510 | 2512 | | |
2511 | 2513 | | |
2512 | 2514 | | |
2513 | 2515 | | |
| 2516 | + | |
| 2517 | + | |
2514 | 2518 | | |
2515 | 2519 | | |
2516 | 2520 | | |
| |||
2556 | 2560 | | |
2557 | 2561 | | |
2558 | 2562 | | |
| 2563 | + | |
| 2564 | + | |
| 2565 | + | |
| 2566 | + | |
| 2567 | + | |
| 2568 | + | |
| 2569 | + | |
| 2570 | + | |
| 2571 | + | |
| 2572 | + | |
| 2573 | + | |
2559 | 2574 | | |
2560 | 2575 | | |
2561 | 2576 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
362 | 362 | | |
363 | 363 | | |
364 | 364 | | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
365 | 370 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
0 commit comments