Commit cd265d1
Fix incorrect type narrowing to *NEVER* for array after foreach assignment
- Added hasOffsetValueType check in AssignHandler to prevent using setExistingOffsetValueType when offset is known to not exist in the array
- When the offset definitely doesn't exist (hasOffsetValueType returns no), fall through to setOffsetValueType which correctly widens the key type
- Updated bug-13270b-php8 test expectation to reflect more precise type inference (hasOffsetValue instead of hasOffset)
- New regression test in tests/PHPStan/Analyser/nsrt/bug-13786.php1 parent c009cb0 commit cd265d1
3 files changed
Lines changed: 22 additions & 1 deletion
File tree
- src/Analyser/ExprHandler
- tests/PHPStan/Analyser/nsrt
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
991 | 991 | | |
992 | 992 | | |
993 | 993 | | |
| 994 | + | |
994 | 995 | | |
995 | 996 | | |
996 | 997 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
| 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