-
-
Notifications
You must be signed in to change notification settings - Fork 947
Single-statement inline offset updates cause confusion #5743
Copy link
Copy link
Closed
Labels
Milestone
Description
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!
Reactions are currently unavailable