Do not report generic covariant issue without strict check#5437
Open
VincentLanglet wants to merge 1 commit intophpstan:2.1.xfrom
Open
Do not report generic covariant issue without strict check#5437VincentLanglet wants to merge 1 commit intophpstan:2.1.xfrom
VincentLanglet wants to merge 1 commit intophpstan:2.1.xfrom
Conversation
ondrejmirtes
requested changes
Apr 9, 2026
| $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()), |
Member
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?
Contributor
Author
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
Collaborator
|
This pull request has been marked as ready for review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.