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

False negative with nested if in for loop #4666

Closed
nikophil opened this issue Mar 5, 2021 · 8 comments
Closed

False negative with nested if in for loop #4666

nikophil opened this issue Mar 5, 2021 · 8 comments
Labels
Milestone

Comments

@nikophil
Copy link

nikophil commented Mar 5, 2021

Hello there,

Bug report

Here is an example of the problem.
https://phpstan.org/r/c499e9ad-92a3-47ec-91ba-42d0920dbc06

I got a false negative on this code. I know the code is far from ideal but it actually works, and moreover on the first iteration, the && result is definitely not false...

What's weird is that when you change the if in order to use CONST_2 in both part of the &&, phpstan returns 0 errors, although both parts of the && are unrelated. Or maybe i'm missing something Oo
If i split the && in order to use two nested if, I got no errors as well...

Expected output

no error should be reported.

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Mar 5, 2021
@nikophil
Copy link
Author

nikophil commented Mar 5, 2021

hi @ondrejmirtes

I see the "easy fixes" label, if you point me out which part of code should be updated, I can make a PR

@ondrejmirtes
Copy link
Member

I actually don't know what's going on and why is this reported, probably the left part of the && expression influences something about the right part which shouldn't be happening. "Easy fix" just means that it will not be hard to fix, but it needs to be debugged what's going on in Scope with this situation.

@ondrejmirtes
Copy link
Member

My tip is actually that the TypeSpecifier does something weird with this part: self::CONST_1 === $object->getType() but I can be wrong.

@phpstan-bot
Copy link
Contributor

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

@@ @@
-13: Result of && is always false.
+ 9: Method HelloWorld::test() is unused.
+13: Result of && is always false.
+22: Property MyObject::$type is never written, only read.
Full report
Line Error
9 Method HelloWorld::test() is unused.
13 Result of && is always false.
22 Property MyObject::$type is never written, only read.

@phpstan-bot
Copy link
Contributor

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

@@ @@
-13: Result of && is always false.
+13: Result of && is always false.
+ 9: Method HelloWorld::test() is unused.
+22: Property MyObject::$type is never written, only read.
Full report
Line Error
13 Result of && is always false.
9 Method HelloWorld::test() is unused.
22 Property MyObject::$type is never written, only read.

@phpstan-bot
Copy link
Contributor

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

@@ @@
-13: Result of && is always false.
+ 9: Method HelloWorld::test() is unused.
+22: Property MyObject::$type is never written, only read.
Full report
Line Error
9 Method HelloWorld::test() is unused.
22 Property MyObject::$type is never written, only read.

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@4321374

@github-actions
Copy link

github-actions bot commented Apr 3, 2022

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 Apr 3, 2022
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

3 participants