vimeo / psalm

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

Invalid type detect after AND condition #11083

Open vjik opened 3 weeks ago

vjik commented 3 weeks ago

https://psalm.dev/r/d946add113

In this case RedundantCondition is invalid.

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

I found these snippets:

https://psalm.dev/r/d946add113 ```php value === $b->value; } } function isEqual(?Obj $a, ?Obj $b): bool { if ($a === null && $b === null) { return true; } /** @psalm-trace $a, $b */ if ( ($a === null && $b !== null) || ($a !== null && $b === null) ) { return false; } return $a->isEqual($b); } ``` ``` Psalm output (using commit 16b24bd): ERROR: RedundantCondition - 22:25 - Obj can never contain null ERROR: RedundantCondition - 23:13 - Obj can never contain null INFO: Trace - 21:5 - $a: Obj INFO: Trace - 21:5 - $b: Obj ```