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

@phpstan-ignore-line not working on last array line #4759

Closed
WillyReyno opened this issue Mar 29, 2021 · 6 comments
Closed

@phpstan-ignore-line not working on last array line #4759

WillyReyno opened this issue Mar 29, 2021 · 6 comments
Labels

Comments

@WillyReyno
Copy link

WillyReyno commented Mar 29, 2021

Bug report

When trying to ignore a few specific lines within an array I noticed that // @phpstan-ignore-line was not working if my array contained only one key or if the key I was trying to ignore was the last one.

Code snippet that reproduces the problem

Last key not ignored

The following code where $a & $c dont exist on $device

[
    'a' => $device->a, // @phpstan-ignore-line
    'b' => $device->b,
    'c' => $device->c, // @phpstan-ignore-line
];

PHPStan only ignores $a while $c should also have been ignored.

 ------ ----------------------------------------------------------- 
  Line   MyClass.php         
 ------ ----------------------------------------------------------- 
  188    Access to an undefined property App\Models\Device::$c.   

Only key not ignored

[
    'a' => $device->a, // @phpstan-ignore-line
];

PHPStan reports :

 ------ ----------------------------------------------------------- 
  Line   MyClass.php  
 ------ ----------------------------------------------------------- 
  186    Access to an undefined property App\Models\Device::$a.   

Expected output

PHPStan shouldn't have reported the ignored lines.

@mergeable
Copy link

mergeable bot commented Mar 29, 2021

This bug report is missing a link to reproduction on phpstan.org.

It will most likely be closed after manual review.

@WillyReyno
Copy link
Author

Link to reproduction : https://phpstan.org/r/c34b3c94-72d4-44ab-a8ed-a883afd57af7

@mvorisek
Copy link
Contributor

I belive this is duplicate of #4750

@phpstan-bot
Copy link
Contributor

@WillyReyno After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
- 9: Access to an undefined property object::$b.
-13: Access to an undefined property object::$a.
+No errors

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@9474696

@github-actions
Copy link

github-actions bot commented Dec 8, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants