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

Assigment to private property of current class given child class is broken #8404

Open
danog opened this issue Aug 12, 2022 · 2 comments
Open
Labels

Comments

@danog
Copy link
Collaborator

danog commented Aug 12, 2022

https://psalm.dev/r/afe6df2159

@psalm-github-bot
Copy link

psalm-github-bot bot commented Aug 12, 2022

I found these snippets:

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

class a {
    private int $value = 0;
    public function handle(a $v): void {
        if ($v instanceof b) {
            $v->value = 123;
        } else {
            $v->value = 321;
        }
    }
}

class b extends a {}
Psalm output (using commit f315647):

ERROR: UndefinedPropertyAssignment - 7:13 - Instance property b::$value is not defined

@orklah
Copy link
Collaborator

orklah commented Aug 12, 2022

Ugh, I hate this thing so much I made a plugin to forbid this: https://github.com/orklah/psalm-strict-visibility

But I guess it's a valid issue still

@orklah orklah added the bug label Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants