Skip to content

False positive smaller.alwaysTrue (2.3.0 regression) #15420

Open
phpstan/phpstan-src
#6744

Description

@michalbundyra

Bug report

Since 2.3.0, PHPStan reports a for loop condition as always true, as if the loop could only run once. 2.2.17 does not report it.

class Test {
	/** @param string[] $cards */
	public function f(array $cards): void
	{
	    for ($i = 0; $i < 10; $i++) {
	        $seen = [];
	        $later = [];
	        foreach ($cards as $card) {
	            if (array_key_exists($card, $seen)) {
	                $later[] = $card;
	                continue;
	            }
	            $seen[$card] = true;
	        }
	        if ($later !== []) {
	            $cards = $later;
	        } else {
	            break;
	        }
	    }
	}
}

Code snippet that reproduces the problem

https://phpstan.org/r/521b79d1-abc0-4acb-a5c4-d43038643830

Expected output

No errors

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

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions