-
-
Notifications
You must be signed in to change notification settings - Fork 863
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
covariant return type error not detected #9014
Comments
Why is this a problem? You already have the error for |
in our case |
Yeah, but |
ok, let me be more precise about the layers involved :-). the base-package contains the project which consumes the base-package via composer declares only the only when all 3 classes are on the analyzed path, I get the error |
Oh right, didn't realize that https://phpstan.org/r/d645ea74-7b18-4145-8488-e5bba9864797 is valid. |
Another example https://phpstan.org/r/6671900f-0059-4169-a188-9437907e2c47 |
@staabm After the latest push in 1.11.x, PHPStan now reports different result with your code snippet: @@ @@
+PHP 7.4 – 8.2 (4 errors)
+==========
+
7: Method base::renderForUser() has no return type specified.
17: Method middle::renderForUser() should return string but return statement is missing.
-28: Method extended::renderForUser() has no return type specified.
+28: Method extended::renderForUser() has no return type specified.
+28: Return type mixed of method extended::renderForUser() is not covariant with return type string of method middle::renderForUser().
+
+PHP 7.2 – 7.3 (4 errors)
+==========
+
+ 7: Method base::renderForUser() has no return type specified.
+17: Method middle::renderForUser() should return string but return statement is missing.
+28: Method extended::renderForUser() has no return type specified.
+28: Return type mixed of method extended::renderForUser() is not compatible with return type string of method middle::renderForUser(). Full reportPHP 7.4 – 8.2 (4 errors)
PHP 7.2 – 7.3 (4 errors)
|
@staabm After the latest push in 1.11.x, PHPStan now reports different result with your code snippet: @@ @@
+PHP 7.4 – 8.2 (4 errors)
+==========
+
7: Method base::renderForUser() has no return type specified.
15: Method middle::renderForUser() should return string but return statement is missing.
-26: Method extended::renderForUser() has no return type specified.
+26: Method extended::renderForUser() has no return type specified.
+26: Return type mixed of method extended::renderForUser() is not covariant with return type string of method middle::renderForUser().
+
+PHP 7.2 – 7.3 (4 errors)
+==========
+
+ 7: Method base::renderForUser() has no return type specified.
+15: Method middle::renderForUser() should return string but return statement is missing.
+26: Method extended::renderForUser() has no return type specified.
+26: Return type mixed of method extended::renderForUser() is not compatible with return type string of method middle::renderForUser(). Full reportPHP 7.4 – 8.2 (4 errors)
PHP 7.2 – 7.3 (4 errors)
|
@ondrejmirtes After the latest push in 1.11.x, PHPStan now reports different result with your code snippet: @@ @@
-No errors
+15: Method Bar::test() overrides method Foo::test() but misses parameter #2 $test. Full report
|
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. |
Bug report
phpstan can detect covariant return types in situations like https://phpstan.org/r/892b3d92-db4c-4fd3-9d5f-b47fb5bf3355.
detecting these is important, because they turn into fatal errors at runtime https://3v4l.org/jdXiU
Code snippet that reproduces the problem
It turns out though, that phpstan does only compare the method in question with the top-most baseclass.
when more layers of inheritance are involved the covariant type is not detected and the runtime fatal error keeps hidden
https://phpstan.org/r/2c6d3ee9-55cb-4ad9-9afd-c6e293f1b3f2
https://3v4l.org/OPasV
Expected output
A non-ignorable error on line 28
The text was updated successfully, but these errors were encountered: