Commit b3fe1bb
committed
Skip "might not exist" report for string types with integer offsets in union decomposition check
- In NonexistentOffsetInArrayDimFetchCheck, the reportMaybes decomposition
loop flattens union types and checks each member individually. When a
constant string member (e.g. '') returns "no" for an integer offset (e.g. 0),
it incorrectly triggers "might not exist" even though the union-level check
correctly returns "maybe".
- Skip the report when innerType is a string and innerDimType is an integer,
since string offset validity is length-dependent and users typically guard
with length checks through variables that PHPStan cannot track.
- The fix does not affect: definite "does not exist" errors (caught earlier),
non-integer offsets on strings (objects, floats, strings still report), or
array offset checks (completely unaffected).
- Probed analogous cases: non-integer dim types on strings, array offset
decomposition, ArrayDestructuringRule (shares the same check) — all
already correct.1 parent dfe0c76 commit b3fe1bb
3 files changed
Lines changed: 27 additions & 0 deletions
File tree
- src/Rules/Arrays
- tests/PHPStan/Rules/Arrays
- data
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
129 | 132 | | |
130 | 133 | | |
131 | 134 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1326 | 1326 | | |
1327 | 1327 | | |
1328 | 1328 | | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
1329 | 1334 | | |
1330 | 1335 | | |
1331 | 1336 | | |
| |||
| 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 | + | |
0 commit comments