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

@psalm-readonly-allow-private-mutation on promoted property doesn't allow private mutation #7731

Closed
sctice-ifixit opened this issue Feb 24, 2022 · 1 comment · Fixed by #8341

Comments

@sctice-ifixit
Copy link

It looks like the @readonly restriction is picked up, but not the @psalm-allow-private-mutation exception.

https://psalm.dev/r/8c55da797e

Changing the promoted property to a standard class property works as expected.

https://psalm.dev/r/da58a808ef

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/8c55da797e
<?php

class C {
    /** @param int $x */
    public function __construct(
        /** @psalm-readonly-allow-private-mutation */
        public $x
    ) {}
    
    public function f(int $x): void {
        $this->x = $x;
    }
}

$c = new C(10);
$c->f(20);
Psalm output (using commit 997bded):

ERROR: InaccessibleProperty - 11:9 - C::$x is marked readonly
https://psalm.dev/r/da58a808ef
<?php

class C {
    /** @psalm-readonly-allow-private-mutation */
    public int $x;
    
    public function __construct(int $x) {
        $this->x = $x;
    }
    
    public function f(int $x): void {
        $this->x = $x;
    }
}

$c = new C(10);
$c->f(20);
$c->x = 30;
Psalm output (using commit 997bded):

ERROR: InaccessibleProperty - 18:1 - C::$x is marked readonly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants