Skip to content

Nested while loop errors #8643

@zacharylund

Description

@zacharylund

Bug report

PHPStan reports errors for nested while loops.

PHPStan 1.9.2 (and older) does not produce this error, but PHPStan 1.9.3 to 1.9.6 does.

Code snippet that reproduces the problem

https://phpstan.org/r/e7e6df1c-ba29-4fd0-82e7-788f2a202177

<?php declare(strict_types = 1);

$x = 0;

while ($x < 4) { // Comparison operation "<" between 0 and 4 is always true.
	$y = 0;

	while ($y < 6) {
		$y += 1;
	}

	$x += 1;
}

echo 'done'; // Unreachable statement - code above always terminates.

This code produces no errors:

<?php declare(strict_types = 1);

$x = 0;

while ($x < 4) {
	$x += 1;
}

echo 'done';

Expected output

PHPStan should report no errors, but reports two:

Comparison operation "<" between 0 and 4 is always true.
Unreachable statement - code above always terminates.

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