[TypeDeclarationDocblocks] Fix invalid array-in-key docblock when narrowing long array unions - #8430
Merged
Merged
Conversation
…rowing long array unions sharedArrayStructure() returns a full array structure, but narrowToAlwaysKnownArrayType() placed it in the key slot of a new ArrayType, producing invalid types like array<mixed[], mixed>. Return the shared structure directly instead.
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 rectorphp/rector#9865
ClassMethodArrayDocblockParamFromLocalCallsRectorcould emit an invalid docblock with an array type in the array-key slot, e.g.@param array<mixed[], mixed> $data.Cause
When a resolved param type is a union of arrays whose printed form exceeds the max length,
TypeNormalizer::generalizeConstantTypes()narrows it vianarrowToAlwaysKnownArrayType():sharedArrayStructure()already returns a full array structure (e.g.array<int, mixed>), but the code dropped it into the key slot of a newArrayType, yieldingarray<array<int, mixed>, mixed>which prints as the invalidarray<mixed[], mixed>. The variable name$arrayUniqueKeyTypeshows the structure was mistaken for a key type.Fix
Return the shared array structure directly. The heterogeneous case from the issue now narrows to a plain
mixed[], which the existing mixed-array guard skips, so no invalid docblock is written.Added a
skip_*fixture reproducing the exact case from the issue.