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

Single-statement inline offset updates cause confusion #5743

Closed
judahnator opened this issue Oct 5, 2021 · 2 comments
Closed

Single-statement inline offset updates cause confusion #5743

judahnator opened this issue Oct 5, 2021 · 2 comments
Labels
Milestone

Comments

@judahnator
Copy link

Bug report

When comparing two expressions using an incremented value of the same variable as an offset, PHPStan does not see that the offset will change within the comparison and throws an error.

Code snippet that reproduces the problem

The code snippet in my project with this error is as follows:

do {
    // snip
} while ($tokens->readOne(++$offset) instanceof CommaToken && $tokens->readOne(++$offset) instanceof IdentityToken);

However, I can also reproduce this on the playground.

https://phpstan.org/r/6b705626-659e-4753-94a5-756e167526e7

The error given is always a variation of:

  • Result of && is always false.
  • Right side of && is always true.

Expected output

In both examples, since $offset is different in both cases it is possible for both sides of the && to be independent. PHPStan is acting as if it believes that both of the values here are the same.

Did PHPStan help you today? Did it make you happy in any way?

You guys rock!

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Oct 11, 2021
@phpstan-bot
Copy link
Contributor

@judahnator After the latest push in 1.8.x, PHPStan now reports different result with your code snippet:

@@ @@
-8: Right side of && is always true.
+8: Offset 1|int<3, max> does not exist on array{}.
Full report
Line Error
8 `Offset 1

@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 Aug 27, 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