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

Invalid generic type resolution after class instances are created in an if branch #6946

Closed
biozshock opened this issue Mar 30, 2022 · 3 comments · Fixed by phpstan/phpstan-src#1575
Labels
Milestone

Comments

@biozshock
Copy link

Bug report

After an if branch phpstan detects the variable of a wrong type.
Sure moving the apply inside the if fixes the problem, but it smells a lot.

Code snippet that reproduces the problem

https://phpstan.org/r/5c6d4ab7-013c-40cb-a867-da3b42288d4c

Expected output

No errors

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

Thank you everybody for your hard work!

@ondrejmirtes ondrejmirtes added this to the Generics milestone Apr 21, 2022
@phpstan-bot
Copy link
Contributor

@biozshock After the latest push in 1.8.x, PHPStan now reports different result with your code snippet:

@@ @@
-41: Parameter #1 $a of method Foo<B>::apply() expects B, B|C given.
+No errors

@ondrejmirtes
Copy link
Member

/cc @rvanvelzen Regression test please 😊

@github-actions
Copy link

github-actions bot commented Sep 2, 2022

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

Successfully merging a pull request may close this issue.

3 participants