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

Type narrowing should be undone after assignment/modification #5129

Closed
Seldaek opened this issue Jun 3, 2021 · 5 comments
Closed

Type narrowing should be undone after assignment/modification #5129

Seldaek opened this issue Jun 3, 2021 · 5 comments
Labels
Milestone

Comments

@Seldaek
Copy link
Contributor

Seldaek commented Jun 3, 2021

Bug report

If a type is narrowed but then the variable changes, it is detected correctly with local variables, but with object properties it does not seem to be the case.

Code snippet that reproduces the problem

https://phpstan.org/r/9aac1f93-cbcc-497d-bd75-79e224ac4838

Expected output

No error

Did PHPStan help you today? Did it make you happy in any way?

Yes yes, cleaning things up :)

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Jun 3, 2021
@phpstan-bot
Copy link
Contributor

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

@@ @@
  5: Property HelloWorld::$foo has no typehint specified.
+10: Comparison operation ">" between 0 and 0 is always false.
 15: Comparison operation ">" between 0 and 0 is always false.
Full report
Line Error
5 Property HelloWorld::$foo has no typehint specified.
10 Comparison operation ">" between 0 and 0 is always false.
15 Comparison operation ">" between 0 and 0 is always false.

@Seldaek
Copy link
Contributor Author

Seldaek commented Jul 14, 2021

Updated snippet because it doesn't really seem like things improved :) https://phpstan.org/r/77218913-41c8-4d15-8a46-b9e03a49c221 it appears with dumptype that the type has changed after being assigned 'x', but the error at line 17 makes no sense to me.

@ondrejmirtes
Copy link
Member

The bot message didn't say it was fixed, it was related to PHPStan being more smart about strlen :)

But your message sparked off an idea in my head that this really isn't that hard to fix it, and it worked on the first try :) So it's fixed: phpstan/phpstan-src@4220e43

@Seldaek
Copy link
Contributor Author

Seldaek commented Jul 15, 2021

Ok that looks great, thanks!

@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 Aug 16, 2021
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