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

@return static in inheritance through extending AND implementing is not working correctly #3580

Closed
josefsabl opened this issue Jul 8, 2020 · 12 comments
Labels
Milestone

Comments

@josefsabl
Copy link

Bug report

Not sure how to better explain the situation. Please see the code snippet.

Code snippet that reproduces the problem

https://phpstan.org/r/7ee5959d-2f86-40af-b006-e9b30d129ca0

Expected output

No error.

@ondrejmirtes
Copy link
Member

For some reason the PHPDoc isn't inherited but should be, this works: https://phpstan.org/r/ba0bfb07-1237-47cd-a61f-5d3bb34a6ff5

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Jul 8, 2020
@josefsabl
Copy link
Author

Yes! This is my workaround. Thank you :-)

@phpstan phpstan deleted a comment from phpstan-bot Mar 3, 2021
@phpstan phpstan deleted a comment from phpstan-bot Mar 3, 2021
@phpstan-bot
Copy link
Contributor

@josefsabl After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
+PHP 7.4 – 8.0 (1 error)
+==========
+
+26: Method TheFooMaker::make() should return TheFoo but returns BaseFoo.
+
+PHP 7.1 – 7.3 (2 errors)
+==========
+
+14: Return type BaseFoo of method BaseFoo::getClone() is not compatible with return type TheBaseFoo of method TheBaseFoo::getClone().
 26: Method TheFooMaker::make() should return TheFoo but returns BaseFoo.
Full report

PHP 7.4 – 8.0 (1 error)

Line Error
26 Method TheFooMaker::make() should return TheFoo but returns BaseFoo.

PHP 7.1 – 7.3 (2 errors)

Line Error
14 Method TheFooMaker::make() should return TheFoo but returns BaseFoo.
26 Method TheFooMaker::make() should return TheFoo but returns BaseFoo.

@phpstan-bot
Copy link
Contributor

@ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-No errors
+PHP 7.4 – 8.0
+==========
+
+No errors
+
+PHP 7.1 – 7.3 (1 error)
+==========
+
+17: Return type BaseFoo of method BaseFoo::getClone() is not compatible with return type TheBaseFoo of method TheBaseFoo::getClone().
Full report

PHP 7.4 – 8.0

No errors

PHP 7.1 – 7.3 (1 error)

Line Error
17 Return type BaseFoo of method BaseFoo::getClone() is not compatible with return type TheBaseFoo of method TheBaseFoo::getClone().

@phpstan-bot
Copy link
Contributor

@josefsabl After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
+PHP 7.4 – 8.1 (1 error)
+==========
+
+26: Method TheFooMaker::make() should return TheFoo but returns BaseFoo.
+
+PHP 7.1 – 7.3 (2 errors)
+==========
+
+14: Return type BaseFoo of method BaseFoo::getClone() is not compatible with return type TheBaseFoo of method TheBaseFoo::getClone().
 26: Method TheFooMaker::make() should return TheFoo but returns BaseFoo.
Full report

PHP 7.4 – 8.1 (1 error)

Line Error
26 Method TheFooMaker::make() should return TheFoo but returns BaseFoo.

PHP 7.1 – 7.3 (2 errors)

Line Error
14 Return type BaseFoo of method BaseFoo::getClone() is not compatible with return type TheBaseFoo of method TheBaseFoo::getClone().
26 Method TheFooMaker::make() should return TheFoo but returns BaseFoo.

@phpstan-bot
Copy link
Contributor

@ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-No errors
+PHP 7.4 – 8.1
+==========
+
+No errors
+
+PHP 7.1 – 7.3 (1 error)
+==========
+
+17: Return type BaseFoo of method BaseFoo::getClone() is not compatible with return type TheBaseFoo of method TheBaseFoo::getClone().
Full report

PHP 7.4 – 8.1

No errors

PHP 7.1 – 7.3 (1 error)

Line Error
17 Return type BaseFoo of method BaseFoo::getClone() is not compatible with return type TheBaseFoo of method TheBaseFoo::getClone().

@phpstan-bot
Copy link
Contributor

@josefsabl After the latest push in 1.8.x, PHPStan now reports different result with your code snippet:

@@ @@
+PHP 7.4 – 8.2 (1 error)
+==========
+
+26: Method TheFooMaker::make() should return TheFoo but returns BaseFoo.
+
+PHP 7.1 – 7.3 (2 errors)
+==========
+
+14: Return type BaseFoo of method BaseFoo::getClone() is not compatible with return type TheBaseFoo of method TheBaseFoo::getClone().
 26: Method TheFooMaker::make() should return TheFoo but returns BaseFoo.
Full report

PHP 7.4 – 8.2 (1 error)

Line Error
26 Method TheFooMaker::make() should return TheFoo but returns BaseFoo.

PHP 7.1 – 7.3 (2 errors)

Line Error
14 Return type BaseFoo of method BaseFoo::getClone() is not compatible with return type TheBaseFoo of method TheBaseFoo::getClone().
26 Method TheFooMaker::make() should return TheFoo but returns BaseFoo.

@phpstan-bot
Copy link
Contributor

@ondrejmirtes After the latest push in 1.8.x, PHPStan now reports different result with your code snippet:

@@ @@
-No errors
+PHP 7.4 – 8.2
+==========
+
+No errors
+
+PHP 7.1 – 7.3 (1 error)
+==========
+
+17: Return type BaseFoo of method BaseFoo::getClone() is not compatible with return type TheBaseFoo of method TheBaseFoo::getClone().
Full report

PHP 7.4 – 8.2

No errors

PHP 7.1 – 7.3 (1 error)

Line Error
17 Return type BaseFoo of method BaseFoo::getClone() is not compatible with return type TheBaseFoo of method TheBaseFoo::getClone().

@phpstan-bot
Copy link
Contributor

@josefsabl After the latest push in 1.11.x, PHPStan now reports different result with your code snippet:

@@ @@
+PHP 7.4 – 8.3 (1 error)
+==========
+
+26: Method TheFooMaker::make() should return TheFoo but returns BaseFoo.
+
+PHP 7.1 – 7.3 (2 errors)
+==========
+
+14: Return type BaseFoo of method BaseFoo::getClone() is not compatible with return type TheBaseFoo of method TheBaseFoo::getClone().
 26: Method TheFooMaker::make() should return TheFoo but returns BaseFoo.
Full report

PHP 7.4 – 8.3 (1 error)

Line Error
26 Method TheFooMaker::make() should return TheFoo but returns BaseFoo.

PHP 7.1 – 7.3 (2 errors)

Line Error
14 Return type BaseFoo of method BaseFoo::getClone() is not compatible with return type TheBaseFoo of method TheBaseFoo::getClone().
26 Method TheFooMaker::make() should return TheFoo but returns BaseFoo.

@phpstan-bot
Copy link
Contributor

@ondrejmirtes After the latest push in 1.11.x, PHPStan now reports different result with your code snippet:

@@ @@
-No errors
+PHP 7.4 – 8.3
+==========
+
+No errors
+
+PHP 7.1 – 7.3 (1 error)
+==========
+
+17: Return type BaseFoo of method BaseFoo::getClone() is not compatible with return type TheBaseFoo of method TheBaseFoo::getClone().
Full report

PHP 7.4 – 8.3

No errors

PHP 7.1 – 7.3 (1 error)

Line Error
17 Return type BaseFoo of method BaseFoo::getClone() is not compatible with return type TheBaseFoo of method TheBaseFoo::getClone().

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src#2803

Copy link

github-actions bot commented Jan 9, 2024

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

No branches or pull requests

3 participants