Skip to content

List (key) in by-reference param is checked too strictly #12330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
rudiedirkx opened this issue Dec 27, 2024 · 1 comment · May be fixed by phpstan/phpstan-src#3964
Open

List (key) in by-reference param is checked too strictly #12330

rudiedirkx opened this issue Dec 27, 2024 · 1 comment · May be fixed by phpstan/phpstan-src#3964
Labels
Milestone

Comments

@rudiedirkx
Copy link

Bug report

If I set an existing key in a list, Phpstan complains about it not being a list anymore. (I think that's what the complaint is about, it's not very readable.) But the keys didn't change, or the order, only a part inside a list element. If I type the list as array<int, ABC> there's no problem, because any key allowed I guess, but hinted as list<ABC> is's an error.

Code snippet that reproduces the problem

https://phpstan.org/r/47c1de12-667b-42f9-93de-5b0464cad896

Expected output

No error, because no list keys/indexes are changed. The mixed (level 6) isn't a part of this bug.

Simpler reproduction without mixed: https://phpstan.org/r/c4dd4b76-92d6-4b30-a489-858fb6f4d932

Did PHPStan help you today? Did it make you happy in any way?

No response

@rudiedirkx
Copy link
Author

Also, maybe for Phpstan 3, the error could be so much more readable with a slight change. Instead of

Parameter X expects Y, Z given.

it would be so much more readable if the Y and Z were more separated, not just with a , which appears everywhere already:

Parameter X expects Y, but Z given.

Like that, it's easy to see where Y ends and Z starts. This is a mess:

Parameter X expects array{items: list}, array{items: array{}}|array{items: non-empty-array<int<0, max>, string>} given.

Which comma separates Y from Z?

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Jan 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants