Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FalsePositive ImpureVariable in constructor #10974

Open
VincentLanglet opened this issue May 15, 2024 · 1 comment · May be fixed by #10990
Open

FalsePositive ImpureVariable in constructor #10974

VincentLanglet opened this issue May 15, 2024 · 1 comment · May be fixed by #10990

Comments

@VincentLanglet
Copy link
Contributor

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

Copy link

I found these snippets:

https://psalm.dev/r/ca5cc043f0
<?php

class Foo
{
    private int $int;
    
    /** @psalm-pure */
    public function __construct(int $int) 
    {
        $this->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

class Foo
{   
    /** @psalm-pure */
    public function __construct(private int $int) 
    {
    }
}

class Factory
{
    /** @psalm-pure */
    public function getFoo(): Foo
    {
        return new Foo(42);
    }
}
Psalm output (using commit 16b24bd):

No issues!

@ghostwriter ghostwriter linked a pull request May 24, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant