vimeo / psalm

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

match instanceof does not work as expected #7937

Open oleg-andreyev opened 2 years ago

oleg-andreyev commented 2 years ago

psalm does not take into account "match" condition.

https://psalm.dev/r/5c4581018e

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

I found these snippets:

https://psalm.dev/r/5c4581018e ```php $entity->getChannels(), $entity instanceof Channel => [$entity], }; ``` ``` Psalm output (using commit f960d71): ERROR: UndefinedMethod - 22:73 - Method Channel::getChannels does not exist ```
AndrolGenhald commented 2 years ago

Also, for the example the instanceof Product and instanceof Category should be marked as redundant since $entity is known to be a Channel.

oleg-andreyev commented 2 years ago

Also, for the example the instanceof Product and instanceof Category should be marked as redundant since $entity is known to be a Channel.

but $entity could be Product or Category. in that case issue is different https://psalm.dev/r/1c37515a7b

AndrolGenhald commented 2 years ago

Looks like it's the multiple conditions with the , causing the issue then: https://psalm.dev/r/808176fcf6

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

I found these snippets:

https://psalm.dev/r/808176fcf6 ```php $entity->getChannels(), $entity instanceof Category => $entity->getChannels(), $entity instanceof Channel => [$entity], }; ``` ``` Psalm output (using commit f960d71): No issues! ```