vimeo / psalm

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

Psalter MissingPureAnnotation doesn't work when function returns static values #9218

Open kkmuffme opened 1 year ago

kkmuffme commented 1 year ago

https://psalm.dev/r/1b09635ea2

Psalter MissingPureAnnotation should add @psalm-pure here, but it doesn't. (same issue also when we have an array with static or partially static values)

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

I found these snippets:

https://psalm.dev/r/1b09635ea2 ```php
orklah commented 1 year ago

This seems intentional: https://github.com/vimeo/psalm/blob/c55692035219da63aa11de1ccc8a060620e091db/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php#L468

I have no idea why though... You could try to drop that and see if some test fail

kkmuffme commented 1 year ago

@muglug do you have any memory why you excluded static string returns from having @psalm-pure added?

&& !$inferred_return_type->isSingleIntLiteral()
&& !$inferred_return_type->isSingleStringLiteral()

https://github.com/vimeo/psalm/commit/10f7031080bbdf776bb13340c351338bc92a61e4