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

Falsy Type after for condition #5328

Closed
staabm opened this issue Jul 18, 2021 · 6 comments
Closed

Falsy Type after for condition #5328

staabm opened this issue Jul 18, 2021 · 6 comments

Comments

@staabm
Copy link
Contributor

staabm commented Jul 18, 2021

Feature request

Analog to the fix in https://github.com/phpstan/phpstan-src/blob/3166ba31a8768979a40e55f1bbfea9ba4449a3d8/tests/PHPStan/Analyser/data/bug-5322.php

i would expect this to apply to for-loops
https://phpstan.org/r/896b762d-0edd-4775-8057-ad47fcbfd5ec

(The example is a bit theoretical though)

@ondrejmirtes
Copy link
Member

Hi, please contribute the fix by yourself, that commit has everything you need. It might also apply to do-while loop too.

Also please understand that when majority of new feature requests come from a single person, I have to internally rate limit implementing those feature requests myself so I can serve the whole userbase equally. Thanks for understanding.

@staabm
Copy link
Contributor Author

staabm commented Jul 18, 2021

Thats totally fine. Just want to get in contact first to get your opinion on the case.

It might also apply to do-while loop too.

I checked this case already and came to the conclusion, that it works fine

@ondrejmirtes
Copy link
Member

Yeah, I was excited about the while loop report, it was an obvious hole 😊

@phpstan-bot
Copy link
Contributor

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

@@ @@
-15: Method Bug5322\Foo::doBar() has no return typehint specified.
+15: Method Bug5322\Foo::doBar() has no return type specified.
 22: Expected type int, actual: int|null
Full report
Line Error
15 Method Bug5322\Foo::doBar() has no return type specified.
22 `Expected type int, actual: int

@ondrejmirtes
Copy link
Member

I think PHPStan got it right, it can be int|null. Feel free to open a new issue if you find a for-loop related bug :)

@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.
Projects
None yet
Development

No branches or pull requests

3 participants