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

Support for endless loops #3573

Open
wants to merge 6 commits into
base: 1.12.x
Choose a base branch
from
Open

Conversation

herndlm
Copy link
Contributor

@herndlm herndlm commented Oct 14, 2024

Closes phpstan/phpstan#6807
Closes phpstan/phpstan#8463
Closes phpstan/phpstan#9374

analogue to while. contains also a slight simplification in the setting of $isAlwaysTerminating for while loops to keep this more in sync.

I had to switch the 2 test blocks in tests/PHPStan/Rules/Comparison/data/strict-comparison.php because the first one would be never exiting endless loop after this change, which would make the second one dead code and not testing anything useful any more.

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not change anything about while. Change only for. After that is merged, you can send the while change as another PR and then we can think about it.

@herndlm
Copy link
Contributor Author

herndlm commented Oct 14, 2024

Please do not change anything about while. Change only for. After that is merged, you can send the while change as another PR and then we can think about it.

It shouldn't change anything, just merges the elseif/else , so only refactor. But I might be overlooking something and can revert it again 😊

@herndlm
Copy link
Contributor Author

herndlm commented Oct 14, 2024

adapted. the failing test cases seem to be OK, since in https:/nikic/PHP-Parser/blob/v3.1.5/lib/PhpParser/ParserAbstract.php#L175-L344 there are 2 endless loops and the outer one does not seem to have a break statement. Replacing them with a while (true) makes it fail the same way.

return new StatementResult(
$finalScope,
$finalScopeResult->hasYield() || $hasYield,
false/* $finalScopeResult->isAlwaysTerminating() && $isAlwaysIterable*/,
$isAlwaysTerminating,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like I'm missing $finalScopeResult->isAlwaysTerminating() here. It's related to the failing test we talk above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please update the E2E test so it's not failing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adapted I think. not sure if I did it the right way, but I manually checked-out PHP-Parser and manually run PHPStan like in the test and let it update the baseline there.

@herndlm
Copy link
Contributor Author

herndlm commented Oct 15, 2024

Saw this fixes some more issues, will add regression tests..
UPDATE: added, those were basically duplicates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants