-
-
Notifications
You must be signed in to change notification settings - Fork 947
Covariance problem with template type with $this and static #9195
Copy link
Copy link
Closed
Description
Bug report
In #9153 (comment) I was advised to use @template instead of @template-covariant. But then I get another phpstan error:
Method MethodMock::methodName() should return MagicMethod<static(MethodMock)> but returns
MagicMethod<$this(MethodMock)>.
Template type TTargetClass on class MagicMethod is not covariant. Learn more:
[What's Up With @template-covariant?](https://phpstan.org/blog/whats-up-with-template-covariant)
I would say the phpstan error (with @template) is wrong, as $this is strictly a subtype of static.
Code snippet that reproduces the problem
https://phpstan.org/r/6897d3da-b2b5-4a31-b740-927310bd6e72 (with @template-covariant)
https://phpstan.org/r/75af0bc1-1122-4734-8b36-b8cc966c32df (with @template)
Expected output
no error
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels