vimeo / psalm

A static analysis tool for finding errors in PHP applications
https://psalm.dev
MIT License
5.54k stars 659 forks source link

Don't allow unpacking non-iterable #5453

Open AndrolGenhald opened 3 years ago

AndrolGenhald commented 3 years ago

This should be an InvalidArgument: https://psalm.dev/r/410b622a1f It's currently allowed because the type can be an iterable, but it should be disallowed if the type can be anything other than iterable.

psalm-github-bot[bot] commented 3 years ago

I found these snippets:

https://psalm.dev/r/410b622a1f ```php |object */ $test = new \stdClass(); foo(...$test); ``` ``` Psalm output (using commit 9f3f420): No issues! ```
weirdan commented 3 years ago

This should be an InvalidArgument

More precisely, it should be PossiblyInvalidArgument.

AndrolGenhald commented 3 years ago

I'm not sure I fully understand the difference between InvalidArgument and PossiblyInvalidArgument. Should psalm always emit PossiblyInvalidArgument when it's possible the argument has the correct type?

weirdan commented 3 years ago

Should psalm always emit PossiblyInvalidArgument when it's possible the argument has the correct type?

Yes, if an argument type has an intersection with the required parameter type then it's a possibly invalid call: https://psalm.dev/r/686b176d87

InvalidScalarArgument, however, currently doesn't have it's Possibly* counterpart, so this can be a bit confusing.

psalm-github-bot[bot] commented 3 years ago

I found these snippets:

https://psalm.dev/r/686b176d87 ```php