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

Using @phpstan-ignore-line after already ignored line fails #3563

Closed
davidbrnovjak opened this issue Jul 2, 2020 · 9 comments
Closed

Using @phpstan-ignore-line after already ignored line fails #3563

davidbrnovjak opened this issue Jul 2, 2020 · 9 comments
Labels
Milestone

Comments

@davidbrnovjak
Copy link

Bug report

Trying to ignore one line in code with @phpstan-ignore-line fails if previous line was already marked to ignore.

Code snippet that reproduces the problem

Using two @phpstan-ignore-line doesn’t work
https://phpstan.org/r/fbb053a0-9a30-4167-8385-cee47c509f9e

Using @phpstan-ignore-line after @phpstan-ignore-next-line doesn’t work either
https://phpstan.org/r/b73c58e0-22df-4e54-80c4-27311e7a091b

But using @phpstan-ignore-next-line works
https://phpstan.org/r/ebc7d3f9-d031-4793-8fb6-35e8564df7c1

Bug or feature? :)

Expected output

Both lines should be ignored

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Jul 27, 2020
@phpstan-bot
Copy link
Contributor

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

@@ @@
 6: Else branch is unreachable because ternary operator condition is always true.
-6: Strict comparison using !== between array() and false will always evaluate to true.
+6: Strict comparison using !== between array{} and false will always evaluate to true.
Full report
Line Error
6 Else branch is unreachable because ternary operator condition is always true.
6 Strict comparison using !== between array{} and false will always evaluate to true.

@phpstan-bot
Copy link
Contributor

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

@@ @@
 7: Else branch is unreachable because ternary operator condition is always true.
-7: Strict comparison using !== between array() and false will always evaluate to true.
+7: Strict comparison using !== between array{} and false will always evaluate to true.
Full report
Line Error
7 Else branch is unreachable because ternary operator condition is always true.
7 Strict comparison using !== between array{} and false will always evaluate to true.

@canvural
Copy link
Contributor

canvural commented Oct 21, 2021

Is it possible that this is PHP-Parser bug?

image

The Arg node on line 5 does not have comments in attributes. The second Arg node has but the line number is 5.

image

Also in the above case, none of the nodes have comments attribute.

Shorter code to reproduce:

<?php

array_merge(
	[], // First comment
  	[], // Second comment
);

@ondrejmirtes
Copy link
Member

@canvural Yeah, Nikita told me to read the comments directly from tokens: nikic/PHP-Parser#742

@canvural
Copy link
Contributor

nikic/PHP-Parser#791 maybe.

@phpstan-bot
Copy link
Contributor

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

@@ @@
-6: Else branch is unreachable because ternary operator condition is always true.
-6: Strict comparison using !== between array() and false will always evaluate to true.
+No errors

@phpstan-bot
Copy link
Contributor

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

@@ @@
-7: Else branch is unreachable because ternary operator condition is always true.
-7: Strict comparison using !== between array() and false will always evaluate to true.
+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