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

Comparison operation "<" between int<min, X> and Y is always true. in for loop #3264

Closed
mehdibo opened this issue May 8, 2020 · 4 comments
Closed
Labels
Milestone

Comments

@mehdibo
Copy link

mehdibo commented May 8, 2020

Bug report

When using 2 for loops, PHPStan reports:

Comparison operation "<" between int<min, 13> and 40 is always true.

In the snippet, it works fine with $predefinedShops = 1,
but starts bugging from $predefinedShops = 2

Code snippet that reproduces the problem

https://phpstan.org/r/2eda8bb9-48f7-4dbe-8a73-4bc32d9806d6

Expected output

No errors

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone May 8, 2020
@flobee
Copy link

flobee commented Dec 20, 2021

$totalShops = 40;
$predefinedShops = 10;

for ($i = 0; $i < $predefinedShops; $i++)
{
	echo "Do something $i...\n";
}

// i now matches always $totalShops bug
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

for (;$i < $totalShops; $i++)
{
	echo "Do something else $i...\n";
}

@phpstan-bot
Copy link
Contributor

@mehdibo After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-9: Comparison operation "<" between int<min, 13> and 40 is always true.
+9: Comparison operation "<" between int<0, 13> and 40 is always true.
Full report
Line Error
9 Comparison operation "<" between int<0, 13> and 40 is always true.

@phpstan-bot
Copy link
Contributor

@mehdibo After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-9: Comparison operation "<" between int<min, 13> and 40 is always true.
+No errors

@github-actions
Copy link

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 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants