Make contravariant inferences only from pure contravariant positions#27357
Conversation
| @@ -1,3 +1,6 @@ | |||
|
|
|||
|
|
|||
|
|
|||
There was a problem hiding this comment.
I think that these newlines are strange.
| const saveBivariant = bivariant; | ||
| const kind = target.declaration ? target.declaration.kind : SyntaxKind.Unknown; | ||
| // Once we descend into a bivariant signature we remain bivariant for all nested inferences | ||
| bivariant = bivariant || kind === SyntaxKind.MethodDeclaration || kind === SyntaxKind.MethodSignature || kind === SyntaxKind.Constructor; |
There was a problem hiding this comment.
Doesn't this only need to be set on the specifically contravariant comparison within forEachMatchingParameterType? Also, could we not use a single variance variable for both bivariant and contravariant context tracking (seeing as we have a variance enum already)?
There was a problem hiding this comment.
The contravariant flag continues to track whether the position is co- or contra-variant, regardless of whether we've descended into a bivariant position. Doing it this way, using two separate boolean variables, makes the logic that flips the flag easy. I looked at keeping it in a single variable but didn't like the complexity that came with it.
Fixes #27337.