Commit 55773e6
Fix phpstan/phpstan#11705: move fix from MutatingScope to ArrayKeyExistsFunctionTypeSpecifyingExtension
The previous fix in MutatingScope::resolveType() was a workaround that
recomputed ArrayDimFetch types when the dim was narrowed. The root cause
is in ArrayKeyExistsFunctionTypeSpecifyingExtension which stores the
full getIterableValueType() for $arr[$key] when the key is non-constant.
This stored type becomes stale when the key is later narrowed (e.g., in
a switch/case), blocking the correct type from being computed.
The fix: for constant arrays (shaped arrays) without optional keys,
skip storing the dim fetch value type. The type will instead be computed
fresh from the array type and the narrowed key type, giving the correct
specific type. For arrays with optional keys, the stored type is still
needed to prevent false "offset might not exist" errors.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1 parent 2716e22 commit 55773e6
2 files changed
Lines changed: 21 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1043 | 1043 | | |
1044 | 1044 | | |
1045 | 1045 | | |
1046 | | - | |
1047 | | - | |
1048 | | - | |
1049 | | - | |
1050 | | - | |
1051 | | - | |
1052 | | - | |
1053 | | - | |
1054 | | - | |
1055 | | - | |
1056 | | - | |
1057 | | - | |
1058 | | - | |
1059 | | - | |
1060 | | - | |
1061 | | - | |
1062 | | - | |
1063 | | - | |
| 1046 | + | |
1064 | 1047 | | |
1065 | 1048 | | |
1066 | 1049 | | |
| |||
Lines changed: 20 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
57 | 73 | | |
58 | 74 | | |
59 | 75 | | |
| |||
109 | 125 | | |
110 | 126 | | |
111 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
112 | 132 | | |
113 | 133 | | |
114 | 134 | | |
| |||
0 commit comments