Commit 9e394e1
Fix nested dim fetch incorrectly preserving list type after container reset
When processing nested array dim fetch assignments like `$arr[$key][$int] = $value`
where the container was previously reset (`$arr[$key] = []`), the list type was
incorrectly preserved. This happened because `produceArrayDimFetchAssignValueToWrite`
used `setExistingOffsetValueType` (which preserves list structure) based on the
general type from the parent's type system, while the actual tracked container type
was an empty array where the offset couldn't exist.
The fix adds a check at container levels (inner dimensions of nested dim fetches)
to verify that the scope's actual tracked type of the container also supports the
offset before using `setExistingOffsetValueType`. This correctly falls through to
`setOffsetValueType` when the container was just reset to `[]`, which properly
degrades the list type.
This addresses the actual reproducer from phpstan/phpstan#14336 where the previous
IntersectionType::setOffsetValueType fix alone was insufficient.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1 parent e2022ca commit 9e394e1
File tree
2 files changed
+50
-0
lines changed- src/Analyser/ExprHandler
- tests/PHPStan/Analyser/nsrt
2 files changed
+50
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1057 | 1057 | | |
1058 | 1058 | | |
1059 | 1059 | | |
| 1060 | + | |
1060 | 1061 | | |
1061 | 1062 | | |
1062 | 1063 | | |
1063 | 1064 | | |
1064 | 1065 | | |
| 1066 | + | |
1065 | 1067 | | |
1066 | 1068 | | |
1067 | 1069 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 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 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
7 | 55 | | |
8 | 56 | | |
9 | 57 | | |
| |||
0 commit comments