Skip to content

The tracking of always true exception has false positives when a while loop condition involves some impure function #6702

@stof

Description

@stof

Bug report

In Scssphp, I got good results in my parsing code regarding the tracking of which function will return the same thing again on next call, by tagging functions of the scanner that moves the position with @phpstan-impure.
I only got one issue when a while condition involves 2 conditions, with the second one calling that impure function. phpstan reports that the first part of the condition is always true. However, this is not actually true. The first part of the condition is indeed always true for the first iteration, but the second half of the condition being impure means that the state won't be the same anymore on the next iteration.

To me, it looks like the analyser does not properly account for the fact that 2 code paths are reaching that method calls, with only one of them being always true.

Code snippet that reproduces the problem

https://phpstan.org/r/2710cc55-0133-4530-a861-cef0804670db

Expected output

no issue should be reported

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

This tracking of the state of the scanner based on impure vs pure functions is really impressive. It was able to find some dead code in another part of the parser, which even allowed me to remove the corresponding dead code in the reference Sass parser in dart-sass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions