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

Loop boundary is wrongly detected when the initialization is not done "classically" #3310

Closed
lyrixx opened this issue May 18, 2020 · 3 comments
Labels
Milestone

Comments

@lyrixx
Copy link
Contributor

lyrixx commented May 18, 2020

Bug report

Hello,

It looks like the scope of loop variable to not clearly detected

Code snippet that reproduces the problem

https://phpstan.org/r/5cf62680-7651-4d08-bc82-69be0fe581aa

<?php 
declare(strict_types = 1);

function explain(int $bitField): void
{
	for ($i = 0; $i < 5; ++$i) {
	}
	for (; $i < 15; ++$i) {
	}
}

Expected output

no error :)


maybe related to

@lyrixx lyrixx changed the title Loop Loop boundary is wrongly detected when the initialization is not done "classically" May 18, 2020
@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Nov 28, 2020
@phpstan-bot
Copy link
Contributor

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

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

@phpstan-bot
Copy link
Contributor

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

@@ @@
-8: Comparison operation "<" between int<min, 8> and 15 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

3 participants