vimeo / psalm

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

FalsePositive ImpureVariable in constructor #10974

Open VincentLanglet opened 4 months ago

VincentLanglet commented 4 months ago

I expect no error in https://psalm.dev/r/ca5cc043f0

Phpstan does not report this as an error https://phpstan.org/r/700d6a81-675e-4f91-9a6b-d042dc6dccd4

And psalm doesn't report this as an error with promoted properties https://psalm.dev/r/85122515f9

psalm-github-bot[bot] commented 4 months ago

I found these snippets:

https://psalm.dev/r/ca5cc043f0 ```php int = $int; } } class Factory { /** @psalm-pure */ public function getFoo(): Foo { return new Foo(42); } } ``` ``` Psalm output (using commit 16b24bd): ERROR: ImpureVariable - 10:9 - Cannot reference $this in a pure context ```
https://psalm.dev/r/85122515f9 ```php