vimeo / psalm

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

Self-referencing error handler isn't seen to modify referenced variables #5004

Open ciaranmcnulty opened 3 years ago

ciaranmcnulty commented 3 years ago

https://psalm.dev/r/34dab8ef7f [correct link below]

Strangely if the lambda is no longer useing the $prevHandler the issue goes away

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

I found these snippets:

https://psalm.dev/r/34dab8ef7f ```php
muglug commented 3 years ago

I think you pasted the wrong example?

ciaranmcnulty commented 3 years ago

Indeed, apologies https://psalm.dev/r/b0bfd00ad9

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

I found these snippets:

https://psalm.dev/r/b0bfd00ad9 ```php 0) echo 'oops'; } ``` ``` Psalm output (using commit a53cc23): ERROR: TypeDoesNotContainType - 16:9 - Type int(0) for $triggered is never positive-numeric INFO: UnusedVariable - 7:56 - $prevHandler is never referenced or the value is not used INFO: UnusedVariable - 7:5 - $prevHandler is never referenced or the value is not used ```
BackEndTea commented 3 years ago

Strangely if the lambda is no longer useing the $prevHandler the issue goes away

Even switching the variables in the use will fix it 🤔: https://psalm.dev/r/ada532ef74

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

I found these snippets:

https://psalm.dev/r/ada532ef74 ```php 0) echo 'oops'; } ``` ``` Psalm output (using commit ef4afd7): INFO: UnusedVariable - 7:69 - $prevHandler is never referenced or the value is not used INFO: UnusedVariable - 7:5 - $prevHandler is never referenced or the value is not used ```