Repository navigation
Fix array unions, offset types and array_is_list() narrowing found while separating array unions - #7206
Merged
Conversation
…al array
mergeIntoGeneralArray() took only the known keys and values of a shape,
so array{id: mixed, ...<int|string, mixed>} merged with array<string, X>
became array<string, mixed> and lost the int keys the shape may hold.
Amp-Thread-ID: https://ampcode.com/threads/T-01a214a7-48c4-741b-a5d4-b003e2d9a39d
array<mixed~'foo', mixed> compared its key through getIterableKeyType(), which turns the subtracted mixed into every array key, so it claimed to hold every array, also ones with the 'foo' key. Against another general array its key is now compared as written. Amp-Thread-ID: https://ampcode.com/threads/T-01a214a7-48c4-741b-a5d4-b003e2d9a39d
hasOffsetValue('a', *NEVER*) describes no array, so intersecting an
array with it gives never instead of an array with an impossible offset.
Amp-Thread-ID: https://ampcode.com/threads/T-01a214a7-48c4-741b-a5d4-b003e2d9a39d
When the previous pass already holds a general array, the shapes of both passes are now generalized with the general arrays. Comparing the shapes of the two passes on their own only collapsed them into a general array of their keys and values, as array<'count'|'path', *ERROR*>, once a union keeps a shape next to a general array. Amp-Thread-ID: https://ampcode.com/threads/T-01a214a7-48c4-741b-a5d4-b003e2d9a39d
When two members of a union merge into a new type, the scan now starts over, so the new member is also compared with the members before it. (Baz&hasMethod(x))|(Foo~Baz&hasMethod(x)) now becomes Foo&hasMethod(x). Amp-Thread-ID: https://ampcode.com/threads/T-01a214a7-48c4-741b-a5d4-b003e2d9a39d
An intersection as array<int>&hasOffsetValue('a', int) is a non-empty
array although none of its members is one alone, so asking the members
one by one answered maybe.
Amp-Thread-ID: https://ampcode.com/threads/T-01a214a7-48c4-741b-a5d4-b003e2d9a39d
The empty array is a list, so an array that is not a list holds
something. In the false branch of array_is_list(), array<K, V> now
becomes non-empty-array<K, V> and array{a?: string} becomes
array{a: string}.
Amp-Thread-ID: https://ampcode.com/threads/T-01a214a7-48c4-741b-a5d4-b003e2d9a39d
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 found while trying to keep unions of general array types separate (follow-up to #7195, replacing #5506). The policy change itself is not part of this PR; it needs more work on performance first.
array{id: mixed, ...<int|string, mixed>}merged witharray<string, X>becamearray<string, mixed>and lost the int keys the shape may hold. The bug-7976 test now expects an error, and it is a true positive:Arr's iterator comes from the generic-lessArrayObject, so the inner arrays can get int keys.array<mixed~'foo', mixed>compared its key throughgetIterableKeyType(), so it claimed to hold every array, also ones with the'foo'key.hasOffsetValue('a', *NEVER*)describes no array.array<'count'|'path', *ERROR*>(PHPStan's ownIgnoredErrorHelperhit this).tryUnion()made meet the members before it.(Baz&hasMethod(x))|(Foo~Baz&hasMethod(x))now becomesFoo&hasMethod(x).non-empty-arrayhold an intersection that is non-empty as a whole, asarray<int>&hasOffsetValue('a', int).array_is_list()rejects to a non-empty one: the empty array is a list, soarray{a?: string}becomesarray{a: string}in the false branch.The C++ mirrors of
ArrayType,HasOffsetValueType,NonEmptyArrayTypeandMutatingScopeare updated; the test suite passes with and without the extension.