Commit 9dfe8a5
committed
Fix phpstan/phpstan#13773: for loop index inference should only work for lists
- Added isList() check in inferForLoopExpressions() before assigning $array[$i] type
- The inference that $array[$i] exists in `for ($i=0; $i<count($array); $i++)` is
only valid when $array is a list (sequential integer keys starting from 0)
- New regression test in tests/PHPStan/Rules/Arrays/data/bug-13773.php1 parent b24bd5e commit 9dfe8a5
3 files changed
Lines changed: 74 additions & 10 deletions
File tree
- src/Analyser
- tests/PHPStan/Rules/Arrays
- data
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4545 | 4545 | | |
4546 | 4546 | | |
4547 | 4547 | | |
4548 | | - | |
4549 | | - | |
4550 | | - | |
4551 | | - | |
4552 | | - | |
| 4548 | + | |
| 4549 | + | |
| 4550 | + | |
| 4551 | + | |
| 4552 | + | |
| 4553 | + | |
| 4554 | + | |
| 4555 | + | |
| 4556 | + | |
4553 | 4557 | | |
4554 | 4558 | | |
4555 | 4559 | | |
| |||
4566 | 4570 | | |
4567 | 4571 | | |
4568 | 4572 | | |
4569 | | - | |
4570 | | - | |
4571 | | - | |
4572 | | - | |
4573 | | - | |
| 4573 | + | |
| 4574 | + | |
| 4575 | + | |
| 4576 | + | |
| 4577 | + | |
| 4578 | + | |
| 4579 | + | |
| 4580 | + | |
| 4581 | + | |
4574 | 4582 | | |
4575 | 4583 | | |
4576 | 4584 | | |
| |||
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1240 | 1240 | | |
1241 | 1241 | | |
1242 | 1242 | | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
1243 | 1259 | | |
| 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 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
0 commit comments