-
-
Notifications
You must be signed in to change notification settings - Fork 862
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
Wrong resolving of generics inside try/catch block #6353
Comments
I guess that |
Yeah, that's the case in TypeScript. |
@honzatrtik After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-PHP 8.0 – 8.1 (1 error)
+PHP 8.0 – 8.1
==========
-58: Function fromCallbackThatCanThrow() should return Option<T> but returns Option<*NEVER*>.
+No errors
-PHP 7.1 – 7.4 (2 errors)
+PHP 7.1 – 7.4 (1 error)
==========
-22: Promoted properties are supported only on PHP 8.0 and later.
-58: Function fromCallbackThatCanThrow() should return Option<T> but returns Option<*NEVER*>.
+22: Promoted properties are supported only on PHP 8.0 and later. Full reportPHP 8.0 – 8.1No errors PHP 7.1 – 7.4 (1 error)
|
@honzatrtik After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-PHP 8.0 – 8.1 (1 error)
+PHP 8.0 – 8.1
==========
-60: Function fromCallbackThatCanThrow() should return Option<T> but returns Option<*NEVER*>|Option<T>.
+No errors
-PHP 7.1 – 7.4 (2 errors)
+PHP 7.1 – 7.4 (1 error)
==========
-22: Promoted properties are supported only on PHP 8.0 and later.
-60: Function fromCallbackThatCanThrow() should return Option<T> but returns Option<*NEVER*>|Option<T>.
+22: Promoted properties are supported only on PHP 8.0 and later. Full reportPHP 8.0 – 8.1No errors PHP 7.1 – 7.4 (1 error)
|
Fixed: phpstan/phpstan-src@c2b9e71 |
Closes phpstan/phpstan#5757 Closes phpstan/phpstan#5065 Closes phpstan/phpstan#3400 Closes phpstan/phpstan#6353
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. |
Code snippet that reproduces the problem
https://phpstan.org/r/ecf86117-177b-439c-b8e3-4e3040a8b6e2
Ends with
Function fromCallbackThatCanThrow() should return Option<T> but returns Option<*NEVER*>.
Additionally, if we set return values to variable as follows:
https://phpstan.org/r/dca44c7f-7e85-4f99-a66c-0b4629a25901
then the reported error is even more confusing:
Function fromCallbackThatCanThrow() should return Option<T> but returns Option<*NEVER*>|Option<T>.
If
never
is subtype ofT
(its universal subtype - bottom type, so it should be) andT
is covariant, thenOption<never>
should be also subtype ofOption<T>
. SoOption<never>| Option<T>
should beOption<T>
Expected output
No errors should be reported
The text was updated successfully, but these errors were encountered: