Skip to content

Single-statement inline offset updates cause confusion #5743

@judahnator

Description

@judahnator

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions