vimeo / psalm

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

property assignment bug with union and int ranges #10826

Open staabm opened 6 months ago

staabm commented 6 months ago

this should not error https://psalm.dev/r/808fd263bd

psalm-github-bot[bot] commented 6 months ago

I found these snippets:

https://psalm.dev/r/808fd263bd ```php p = $i; } } ``` ``` Psalm output (using commit ef3b018): ERROR: InvalidPropertyAssignmentValue - 22:20 - $this->p with declared type 'int<1, max>|null' cannot be assigned type 'int<0, max>|null' ```
jack-worman commented 6 months ago

Simplified: https://psalm.dev/r/4998359b55

The root issue seems to be -1|positive-int getting wrongly converted to int<-1, max>. Technically it isn't wrong, just more general than it needs to be.

psalm-github-bot[bot] commented 6 months ago

I found these snippets:

https://psalm.dev/r/4998359b55 ```php INFO: UnusedVariable - 8:1 - $a is never referenced or the value is not used ```