Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested while loop errors #8643

Closed
zacharylund opened this issue Jan 3, 2023 · 2 comments
Closed

Nested while loop errors #8643

zacharylund opened this issue Jan 3, 2023 · 2 comments

Comments

@zacharylund
Copy link

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.

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@091fcaf

@github-actions
Copy link

github-actions bot commented Feb 5, 2023

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants