vimeo / psalm

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

class_exists in a multi-line conditional does not assert class existence #7980

Open mr-feek opened 2 years ago

mr-feek commented 2 years ago

Psalm.dev link: https://psalm.dev/r/273dd436a4

Expected Functionality: Psalm is aware that the class will exist within the conditional and does not emit an UndefinedClass error

Notes: Simply removing the rand(0,1) call results in expected behavior. An easy workaround for developers is to just put the class exists check on its own line

Context: Ran into this while doing composer package development for a library that has a suggest key in composer.json for additional functionality.

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

I found these snippets:

https://psalm.dev/r/273dd436a4 ```php
AndrolGenhald commented 2 years ago

Possibly related to #6530.

mr-feek commented 2 years ago

Happy to take a stab at fixing this if someone would be so inclined to give some pointers :)

orklah commented 2 years ago

Cool! Did you check at my comment here: https://github.com/vimeo/psalm/issues/6530#issuecomment-926808964 ?

I analyzed that a while ago and I discovered it looks like an issue of "merging" the phantom_classes property between two context