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

Comparison operation ">" between X and Y is always true #3867

Closed
RubenAtPA opened this issue Sep 14, 2020 · 3 comments
Closed

Comparison operation ">" between X and Y is always true #3867

RubenAtPA opened this issue Sep 14, 2020 · 3 comments

Comments

@RubenAtPA
Copy link

Bug report

In this situation there is an array defined with a fixed number of elements. Within a do-while loop elements are taken of the stack with the method array_shift. Within the do body an if-statements can break from this loop and the while section of the loop tests for the number of remaining elements. PHPStan doesn't recognize this however and fails with the message Comparison operation ">" between X and Y is always true.

Code snippet that reproduces the problem

https://phpstan.org/r/911404cc-308a-4334-ad23-a180a5dfccb7

Expected output

The error should not have been reported, because the list can be exhausted and will return false eventually.

@phpstan-bot
Copy link
Contributor

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

@@ @@
-20: Comparison operation ">" between 2 and 0 is always true.
+20: Comparison operation ">" between 1 and 0 is always true.
Full report
Line Error
20 Comparison operation ">" between 1 and 0 is always true.

@phpstan-bot
Copy link
Contributor

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

@@ @@
-20: Comparison operation ">" between 2 and 0 is always true.
+No errors

@github-actions
Copy link

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 Feb 14, 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