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
Support for @template-contravariant tag #7502
Comments
What's the use-case? Your example doesn't imply anything about the need for contravariant. |
I'll give a different example: https://phpstan.org/r/f19ee206-09de-4b84-968d-5d2a74373228 |
It's not hard to add support for this.
|
Related issue (probably dupe): #3960 |
Yes, please follow the original issue. |
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. |
Feature request
PHPStan currently allows two types of variance for template types in class-likes:
@template
(invariant) and@template-covariant
(covariant). PHPStan also internally supports the third type: contravariant, but lacks support for specifying it for class-likes with a PHPDoc.This is, however, sometimes useful:
The implementation should theoretically be trivial: add support for
@template-contravariant
tag in phpdoc-parser, then correctly parse those tags into respective variance on phpstan side. As far as I understand, the support has been there internally for a long time already.We'll also need to modify https://github.com/phpstan/phpstan-src/blob/f8be122188aa6721cec9872bd61676ee150a5311/src/Rules/Generics/VarianceCheck.php#L53 to check contravariance in parameters.
Did PHPStan help you today? Did it make you happy in any way?
PHPStan is awesome!
The text was updated successfully, but these errors were encountered: