Repository navigation
Keep the members of unions of general arrays apart through joins, writes and foreach - #7237
Merged
Merged
Conversation
ondrejmirtes
force-pushed
the
keep-array-union-members-apart
branch
from
November 28, 2026 05:34
c57482f to
a8b3d2a
Compare
…tes and foreach
- OverlappingArrayUnionRule groups the general arrays among themselves
first; a shape joins a group only when it reaches exactly one, so
array{} no longer links list<X> and array<string, X> into one array.
- ArrayAlgebra::splitConstantArrayAtFiniteValue() also splits a value that
is a union of other types, so list<int>|list<string> accepts
array{int|string}.
- A certain non-null narrowing of $a[$k] drops the array members of $a
whose values cannot hold it, and a write to a tracked offset keeps the
container a list.
- UnionType::accepts() drops the reasons of rejecting members once one
member accepts, so the tip no longer reports an accepted offset.
- foreach over a union of general arrays with disjoint key types ties the
key, the value and the iteratee together by the member.
Closes phpstan/phpstan#15873
Amp-Thread-ID: https://ampcode.com/threads/T-01a21efd-7346-7575-a0dd-5474e0f5c329
A split shape is accepted member by member, which split the arrays among its values again, so shapes nested in each other split into exponentially many shapes (nested-nullable-shape-accepts: 213M to 23.8B instructions). Scalar unions, which [$scalar] for list<A>|list<B> needs, still split. Amp-Thread-ID: https://ampcode.com/threads/T-01a21efd-7346-7575-a0dd-5474e0f5c329
ondrejmirtes
force-pushed
the
keep-array-union-members-apart
branch
from
November 28, 2026 06:15
cc39314 to
5025c06
Compare
A write under a string key to a tracked offset of array{} was intersected
with list, which made the written array never.
Amp-Thread-ID: https://ampcode.com/threads/T-01a21efd-7346-7575-a0dd-5474e0f5c329
This was referenced Nov 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the forms reported in phpstan/phpstan#15873 after 0578e53 (unions of general arrays kept apart, bleeding edge):
foreachandcount()checks no longer mergelist<X>|array<string, X>. Thearray{}of the loop-not-run or empty branch linked both general arrays inOverlappingArrayUnionRule. General arrays are now grouped among themselves, and a shape joins a group only when it reaches exactly one.list<int>|array<string, int>value members apart (same cause as 1).[$scalar]is accepted bylist<string>|list<int>|…:UnionType::accepts()splitsarray{bool|int|…}into its members (viaArrayAlgebra::splitConstantArrayAtFiniteValue()), and joins no longer absorbarray{T}into a list member.is_array($m[$k])onlist<shape>|array<stdClass>drops thearray<stdClass>member, and a nested write to that tracked offset keepslist.Offset 1 (X) does not accept type Xfor an offset that is accepted: a union that accepts drops the reasons of its rejecting members.foreach ($types as $key => $type)over a union of general arrays with disjoint key types ties$key,$typeand$typesby member, sois_int($key)narrows$typeand$types.Not fixed: the key-copying form (
$copy[$key] = $typeoverarray<int, T>|array<string, T>still givesarray<int|string, T>). That would need conditional holders on the iteratee to survive the loop-head merge.The changed shadowed classes (
UnionType,MutatingScope,AssignHandler,ForeachHandler) are ported to turbo-ext. The full test suite passes with and without the extension, and smoke, signature parity and side-by-side pass.Closes phpstan/phpstan#15873