vimeo / psalm

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

variance for constants in not complete switches #5154

Open drealecs opened 3 years ago

drealecs commented 3 years ago

while this detects the constant type variance well: https://psalm.dev/r/5adf725aac this another example, without a default does not work well: https://psalm.dev/r/4506f5108a

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

I found these snippets:

https://psalm.dev/r/5adf725aac ```php
https://psalm.dev/r/4506f5108a ```php
drealecs commented 3 years ago

Actually, I think constants are having more issues... https://psalm.dev/r/ccfde69c1d

If you can point me in the correct direction, I can try to provide a PR, thanks!

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

I found these snippets:

https://psalm.dev/r/ccfde69c1d ```php
orklah commented 2 years ago

First issue is related to switch control flow, not really to constants. The second one is different, I'm not sure how much Psalm understands defined

orklah commented 2 years ago

This is somehow more broken than before...

AndrolGenhald commented 2 years ago

It's actually working fine without the paradoxical condition: https://psalm.dev/r/018a56ccd2 The paradoxical condition somehow forces the constant type to z instead of x|y|z. Having a default case without the paradoxical condition works fine too: https://psalm.dev/r/b6c5c2bc95

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

I found these snippets:

https://psalm.dev/r/018a56ccd2 ```php
https://psalm.dev/r/b6c5c2bc95 ```php
weirdan commented 2 years ago

https://psalm.dev/r/018a56ccd2 https://psalm.dev/r/b6c5c2bc95

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

I found these snippets:

https://psalm.dev/r/018a56ccd2 ```php
https://psalm.dev/r/b6c5c2bc95 ```php
weirdan commented 1 year ago

Original snippets work as expected now.

AndrolGenhald commented 1 year ago

Still seems broken: https://psalm.dev/r/762bc01c78

psalm-github-bot[bot] commented 1 year ago

I found these snippets:

https://psalm.dev/r/762bc01c78 ```php