Skip to content
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

Misleading noisy errors when assigning to offsets of array properties in 1.4 #6397

Closed
dktapps opened this issue Jan 17, 2022 · 5 comments
Closed

Comments

@dktapps
Copy link
Contributor

dktapps commented Jan 17, 2022

Bug report

Since 1.4, the behaviour of assigning wrong things to array offsets has changed.

Before: Array (array<class-string<pocketmine\block\tile\Tile>, string>) does not accept string|false.
After: Property TileFactory::$saveNames (array<class-string<Tile>, string>) does not accept array<class-string<Tile>, bool|string>.

This output is more noisy and misleading, because it suggests the property itself is being assigned to, when what's actually happening is an offset is being assigned.

For complex array types (e.g. shapes) this leads to a duplication of information that makes it very hard to see what the actual problem is.

Code snippet that reproduces the problem

https://phpstan.org/r/d44fc30b-eb39-43ad-aab1-0b0081d8da0d

@ondrejmirtes
Copy link
Member

This is a hard problem, already discussed in: #6367 (comment)

@dktapps
Copy link
Contributor Author

dktapps commented Jan 18, 2022

I think this really needs to be addressed. I've come across multiple errors like this on 1.4, including this one that I spent a whole day staring at in utter confusion until I noticed that the property might be null: https://phpstan.org/r/734214e1-1f1e-4973-8c7e-554169a736e0

@ondrejmirtes
Copy link
Member

I love how precise it is! It's preventing this error: https://3v4l.org/F5MGC

But I don't have ideas how to make the message clearer.

@dktapps
Copy link
Contributor Author

dktapps commented Jan 18, 2022

Yeah, I get that it detected a problem. But I spent a whole day looking at errors like this trying to figure out if it was a PHPStan bug or a problem with my code. Eventually I figured out what was going on. (Turns out the problem was being caused by #6399 in my code and there weren't actually any bugs).

IMO this should be reported something like Cannot use array-access on <type>.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants