Commit 4e94226
Generalize empty-array accessory filter via
Vincent's review on #5568 raised that the explicit
`OversizedArrayType` / `NonEmptyArrayType` filter is too narrow — the
same `array{} & accessory` contradiction could in principle arise with
any accessory whose `accepts(array{})` is `no` (e.g. `HasOffsetType`).
Switch the predicate to `!$accessory->accepts(emptyArray, true)->no()`
so future accessories don't reintroduce the bug.
Notes from the audit:
- `OversizedArrayType::isIterableAtLeastOnce()` returns `maybe`
(relaxed by 8d87c67, "Solve 11703" — an oversized-tagged array
built via conditional pushes can be empty), so the more obvious
`$accessory->isIterableAtLeastOnce()->yes()` predicate would NOT
catch oversized. The `accepts(array{})` predicate is the correct
one because the bug surfaces via accepts-based supertype checks.
- Today only `OversizedArrayType` actually leaks into the common
accessory set via partial presence — `NonEmptyArrayType`,
`HasOffsetType`, `HasOffsetValueType`, `AccessoryArrayListType`
are added to the common set only when ALL inputs carry them, so
no empty input can reach the intersection. The general predicate
is forward-defensive, not currently load-bearing for the other
accessories.
- There is also an internal inconsistency in `OversizedArrayType`
itself: `accepts()` still uses `isIterableAtLeastOnce()->yes()`
while `isIterableAtLeastOnce()` returns `maybe`. That's tracked
as a separate concern in phpstan/phpstan#14560 and is out of
scope here.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>accepts()
1 parent 07e4956 commit 4e94226
1 file changed
Lines changed: 11 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
960 | 960 | | |
961 | 961 | | |
962 | 962 | | |
| 963 | + | |
963 | 964 | | |
964 | 965 | | |
965 | 966 | | |
966 | | - | |
967 | | - | |
968 | | - | |
969 | | - | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
970 | 976 | | |
971 | 977 | | |
972 | | - | |
| 978 | + | |
973 | 979 | | |
974 | 980 | | |
975 | 981 | | |
| |||
0 commit comments