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

Previously working generic for exception class fails #3420

Closed
vojtech-dobes opened this issue Jun 9, 2020 · 3 comments · Fixed by phpstan/phpstan-src#229
Closed

Previously working generic for exception class fails #3420

vojtech-dobes opened this issue Jun 9, 2020 · 3 comments · Fixed by phpstan/phpstan-src#229

Comments

@vojtech-dobes
Copy link

Bug report

We have a generic class, which receives exception class as templated parameter and then uses it to throw. Previously it was recognized by PhpStan, but both on 0.12.26 & 0.12.27 this now fails (both on throw and on @throws phpDoc).

Invalid type TExceptionClass of RuntimeException to throw
PHPDoc tag @throws with type TExceptionClass of Exception is not subtype of Throwable

Code snippet that reproduces the problem

https://phpstan.org/r/a2f79f88-a35e-450d-86d1-86d750e6b21b

Expected output

No error.

@hrach
Copy link
Contributor

hrach commented Jun 9, 2020

Tested with another expected result.

The issue is the ObjectType is "anything that implements/extends the type".

The question asks if "anything implementing Throwable" is superTypeOf the passed "T of Exception". And the correct answer (IMO) is a maybe. As somehow described in #3333, I worry that we need another type.

@ondrejmirtes
Copy link
Member

In case of $e instanceof \Throwable we can be sure it's yes (and that should be fixed).
In case of $e instanceof $throwable it's correctly maybe.

@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 May 17, 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

Successfully merging a pull request may close this issue.

3 participants