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

Constructor property promotion not detected properly. #4386

Closed
kapitancho opened this issue Oct 21, 2020 · 1 comment
Closed

Constructor property promotion not detected properly. #4386

kapitancho opened this issue Oct 21, 2020 · 1 comment
Labels

Comments

@kapitancho
Copy link

There are a few cases which are not detected or incorrectly reported as errors:

  1. The promoted constructor properties are incorrectly reported as INFO: PossiblyUnusedParam - 4:44 - Param Allow negated assignment #1 is never referenced in this method: https://psalm.dev/r/f778aa1dc7
  2. One can attempt to define a regular property and a promoted property with the same name (side by side) and no error is being reported while it should be: https://psalm.dev/r/7efdfcb849
@psalm-github-bot
Copy link

I found these snippets:

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

class Test {
    public function __construct(public int $id, public string $name) {}
}

$test = new Test(1, 'Name');
echo $test->id;
echo $test->name;
Psalm output (using commit fd43ba7):

INFO: PossiblyUnusedParam - 4:44 - Param #1 is never referenced in this method

INFO: PossiblyUnusedParam - 4:63 - Param #2 is never referenced in this method
https://psalm.dev/r/7efdfcb849
<?php

class Test {
    public int $id;
    public function __construct(public int $id) {}
}

new Test(1);
Psalm output (using commit fd43ba7):

INFO: PossiblyUnusedParam - 5:44 - Param #1 is never referenced in this method

INFO: PossiblyUnusedProperty - 5:44 - Cannot find any references to property Test::$id

@muglug muglug added the bug label Oct 21, 2020
@muglug muglug closed this as completed in ad5a8c2 Oct 21, 2020
danog pushed a commit to danog/psalm that referenced this issue Jan 29, 2021
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