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

should return TypeObject of AbstractA|AbstractB but returns AbstractA|AbstractB #7987

Closed
arderyp opened this issue Sep 11, 2022 · 5 comments · Fixed by phpstan/phpstan-src#1724
Labels
Milestone

Comments

@arderyp
Copy link

arderyp commented Sep 11, 2022

Maybe I am missing something?

https://phpstan.org/r/dfa88d94-eb8e-4ab5-8170-455575220e83

Potentially related issue: #4411

@mad-briller
Copy link

mad-briller commented Sep 12, 2022

phpstan currently models types as possibility sets, not control flow, you can learn more from this talk

@arderyp
Copy link
Author

arderyp commented Sep 12, 2022

thanks for the link @mad-briller, I will check out the talk later today. Always happy to learn more about PHPStan!

That said, the error is confusing, and I still don't see how my example is problematic. It saying the function should return TypeObject of AbstractA|AbstractB and it is literally returning TypeObject, which the generic defines as TypeObject of AbstractA|AbstractB.

But, maybe the talk will enlighten me or give me an idea of how to solve this.

@mad-briller
Copy link

mad-briller commented Sep 13, 2022

sorry @arderyp i misunderstood the error mesage myself,

i thought it was stating that because the method is generic over a single class, but has the possibility to return either AbstractA or AbstractB, phpstan was getting confused by that
but judging by the fix provided by @rvanvelzen i was wrong :D

@arderyp
Copy link
Author

arderyp commented Sep 13, 2022

I appreciate the video link anyways :)

@github-actions
Copy link

github-actions bot commented Oct 24, 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 Oct 24, 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