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

Generic return type gets corrupted by throw statement #4422

Closed
vojtech-dobes opened this issue Jan 24, 2021 · 3 comments
Closed

Generic return type gets corrupted by throw statement #4422

vojtech-dobes opened this issue Jan 24, 2021 · 3 comments

Comments

@vojtech-dobes
Copy link

Bug report

I have function with generic callable argument - using generics I describe that the function returns whatever the callback returns.

The problem is when I:

  • pass the callback as anonymous function
  • which actually has native return type hint
  • but throws instead

Code snippet that reproduces the problem

https://phpstan.org/r/d0bf24b0-f404-43f0-b000-1c409ae19aa1#

Expected output

I think the native return type hint shouldn't be overridden by throwing (which I guess resolves it to never), and therefore the snippet above shouldn't report any error. If you think otherwise, could you please explain the philosophy behind that? I've experienced this new behaviour when updating from 67 to 69.

@ondrejmirtes
Copy link
Member

The part that leads to closure type being inferred as never is correct, but this needed fixing: phpstan/phpstan-src@ba4bc4f

@vojtech-dobes
Copy link
Author

That's awesome, thank you!

@github-actions
Copy link

github-actions bot commented May 1, 2021

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

No branches or pull requests

2 participants