-
-
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
Generics inheritance raises errors #3537
Comments
I think I may have the same issue with In this playground https://phpstan.org/r/8e09eb41-fa34-4714-9996-994c911d8910 I have removed |
@hultberg Your error isn't related to OP but rather to #2735. Repeating the constructor in the child class will work for you now: https://phpstan.org/r/8edeab32-683a-4b49-86fa-5213bd955b10 |
@remi-san After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-31: Method DishDoctrineRepository::filter() should return array<Dish> but returns array<Entity>.
31: Parameter #1 $filter of method SearchDoctrineRepository<Entity>::filterEntities() expects Filter<Entity>, DishFilter given. Full report
|
Fixed: phpstan/phpstan-src@4acbc6c You can get rid of the remaining error with |
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
Using v0.12.31
When declaring type implementing or extending a generic type, when this type is passed as a parameter or as a return, it is not considered a subclass of the generic type it implements or extend.
Code snippet that reproduces the problem
This code raises the following errors:
Method DishDoctrineRepository::filter() should return array<Dish> but returns array<Entity>.
Parameter #1 $filter of method SearchDoctrineRepository<Entity>::filterEntities() expects Filter<Entity>, DishFilter given.
It can be found here https://phpstan.org/r/5200477a-9300-454d-bca8-59511b8c51d3
Expected output
Given that
DishDoctrineRepository
extendsSearchDoctrineRepository<Dish>
I expect the return type offilterEntities()
to bearray<Dish>
and notarray<Entity>
as it is detected.And because
DishFilter
extendsFilter<Dish>
, when the method expectsFilter<Dish>
, it should allow to get aDishFilter
.Am I doing something wrong here?
The text was updated successfully, but these errors were encountered: