Skip to content

Reindex constant arrays via shuffle#1438

Merged
ondrejmirtes merged 2 commits intophpstan:1.8.xfrom
herndlm:fix-6138
Jul 1, 2022
Merged

Reindex constant arrays via shuffle#1438
ondrejmirtes merged 2 commits intophpstan:1.8.xfrom
herndlm:fix-6138

Conversation

@herndlm
Copy link
Copy Markdown
Contributor

@herndlm herndlm commented Jun 17, 2022

Closes phpstan/phpstan#6138

While this is an improvement I'm not a 100% happy with it, because the constant array still dictates the same order of values after shuffle, which is not correct. But generalizing it to a normal array would loose the key order I presume? Better ideas?

@herndlm herndlm marked this pull request as ready for review June 17, 2022 19:17
@ondrejmirtes
Copy link
Copy Markdown
Member

I'd say the array should be general (ArrayType) after shuffle because the key => value type association is no longer maintained - ConstantArrayType is no longer correct.

@herndlm
Copy link
Copy Markdown
Contributor Author

herndlm commented Jun 17, 2022

I had the same thought but then we loose the keys I guess. But OK, I'll look into that tomorrow

@herndlm herndlm changed the base branch from 1.7.x to 1.8.x June 30, 2022 12:52
@herndlm
Copy link
Copy Markdown
Contributor Author

herndlm commented Jun 30, 2022

"tomorrow" = ~2 weeks in the parallel universe I was living :)

should be adapted. shuffle leads now to a generic array and re-indexes the keys. The only thing that was lost is the order of the keys which is always 0, 1, 2, .. but I guess we can't retain them at the moment.

@herndlm
Copy link
Copy Markdown
Contributor Author

herndlm commented Jun 30, 2022

Not a 100% happy with this, but I can't come up with something better. Basically something like a shuffled list / shuffled constant array would be needed, but that feels very much like an edge case :)

@herndlm herndlm requested a review from ondrejmirtes June 30, 2022 18:58
@ondrejmirtes ondrejmirtes merged commit addecc7 into phpstan:1.8.x Jul 1, 2022
@ondrejmirtes
Copy link
Copy Markdown
Member

Thank you.

@herndlm herndlm deleted the fix-6138 branch July 1, 2022 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PHPStan does not detect that shuffle() reindexes array keys

2 participants