[TypeDeclaration] Fix AddClosureParamTypeForArrayMapRector to type closure params from array values, not keys#8163
Merged
Conversation
…osure params from array values, not keys
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.
AddClosureParamTypeForArrayMapRectormodeledarray_map()as if it passed(value, key)pairs to the closure — likearray_walk(). It doesn't.array_map()passes values only, positionally: with N array arguments, the i-th closure parameter receives values from the i-th array. Keys are never passed.Because of this, the second closure parameter was typed from the merged key types of all arrays, producing wrong (and often union) types.
Before
got typed as:
$valueiterates$tokensvalues (string), yet it receivedint|string— the merged keys ofarray_keys($tokens)(int) and$tokens(string).After
Each parameter is now typed from the value type of its matching array argument.
Change
$closure->params[$i]is typed fromgetIterableValueType()of the i-th array argument; key handling removed entirely.array_map($fn, ...$arrays)) bail out — positions can't be resolved statically (already covered byskip_tuple).array_keys_and_valuesfixture for the reported case.