vimeo / psalm

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

Allow for deterministic null checks #9625

Open gbirke opened 1 year ago

gbirke commented 1 year ago

https://psalm.dev/r/b95d82f00f

Shows a return type error when a deterministic function is called twice, once with null check, then with an assignment. A workaround would be to store the result in a variable and do the null check on the variable.

But is there another way to do this, maybe mark the lookup function as deterministic/pure, so Psalm can detect and keep the null check?

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

I found these snippets:

https://psalm.dev/r/b95d82f00f ```php ' for allFound ERROR: InvalidReturnType - 9:12 - The declared return type 'array' for allFound is incorrect, got 'list{0: 'blah', 1?: null|string}' ```
orklah commented 1 year ago

Flagging the function as pure should work but it doesn't: https://psalm.dev/r/f587c1f836

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

I found these snippets:

https://psalm.dev/r/f587c1f836 ```php