Do not report generic covariant issue without strict check#5437
Do not report generic covariant issue without strict check#5437VincentLanglet wants to merge 1 commit intophpstan:2.1.xfrom
Conversation
| $type = TypeTraverser::map($type, static function (Type $type, callable $traverse): Type { | ||
| if ($type instanceof GenericObjectType) { | ||
| $type = $type->changeVariances( | ||
| array_fill(0, count($type->getVariances()), TemplateTypeVariance::createBivariant()), |
There was a problem hiding this comment.
What if we changed it to covariant only if it's invariant? Also we might need to do it only if isSuperType is no. So closer to the end of the method?
There was a problem hiding this comment.
Yes I updated to only change invariant to covariant.
But I think I can do it every time and it's easier this way to me. It avoids having to do this strategy in every possible cases (constant array, iterable, etc).
Since invariant checks equals and covariant isSuperTypeOf, I can't think of a false positif to always change covariant to invariant.
220682c to
663cbfa
Compare
663cbfa to
c72d0f3
Compare
|
This pull request has been marked as ready for review. |
| { | ||
| $this->checkTypeAgainstPhpDocType = true; | ||
| $this->strictWideningCheck = false; | ||
| $this->analyse([__DIR__ . '/data/generic-subtype.php'], []); |
There was a problem hiding this comment.
It'd be nice to come up with an example that would still be reported even here. Like Foo<int> vs. Foo<string>.
No description provided.