@@ -3870,26 +3870,32 @@ func (r *Relater) typeArgumentsRelatedTo(sources []*Type, targets []*Type, varia
38703870 } else {
38713871 related = r .c .compareTypesIdentical (s , t )
38723872 }
3873- } else if variance == VarianceFlagsCovariant {
3874- related = r .isRelatedToEx (s , t , RecursionFlagsBoth , reportErrors , nil /*headMessage*/ , intersectionState )
3875- } else if variance == VarianceFlagsContravariant {
3876- related = r .isRelatedToEx (t , s , RecursionFlagsBoth , reportErrors , nil /*headMessage*/ , intersectionState )
3877- } else if variance == VarianceFlagsBivariant {
3878- // In the bivariant case we first compare contravariantly without reporting
3879- // errors. Then, if that doesn't succeed, we compare covariantly with error
3880- // reporting. Thus, error elaboration will be based on the covariant check,
3881- // which is generally easier to reason about.
3882- related = r .isRelatedTo (t , s , RecursionFlagsBoth , false /*reportErrors*/ )
3883- if related == TernaryFalse {
3884- related = r .isRelatedToEx (s , t , RecursionFlagsBoth , reportErrors , nil /*headMessage*/ , intersectionState )
3885- }
38863873 } else {
3887- // In the invariant case we first compare covariantly, and only when that
3888- // succeeds do we proceed to compare contravariantly. Thus, error elaboration
3889- // will typically be based on the covariant check.
3890- related = r .isRelatedToEx (s , t , RecursionFlagsBoth , reportErrors , nil /*headMessage*/ , intersectionState )
3891- if related != TernaryFalse {
3892- related &= r .isRelatedToEx (t , s , RecursionFlagsBoth , reportErrors , nil /*headMessage*/ , intersectionState )
3874+ // Propagate unreliable variance flag
3875+ if r .c .inVarianceComputation && varianceFlags & VarianceFlagsUnreliable != 0 {
3876+ r .c .instantiateType (s , r .c .reportUnreliableMapper )
3877+ }
3878+ if variance == VarianceFlagsCovariant {
3879+ related = r .isRelatedToEx (s , t , RecursionFlagsBoth , reportErrors , nil /*headMessage*/ , intersectionState )
3880+ } else if variance == VarianceFlagsContravariant {
3881+ related = r .isRelatedToEx (t , s , RecursionFlagsBoth , reportErrors , nil /*headMessage*/ , intersectionState )
3882+ } else if variance == VarianceFlagsBivariant {
3883+ // In the bivariant case we first compare contravariantly without reporting
3884+ // errors. Then, if that doesn't succeed, we compare covariantly with error
3885+ // reporting. Thus, error elaboration will be based on the covariant check,
3886+ // which is generally easier to reason about.
3887+ related = r .isRelatedTo (t , s , RecursionFlagsBoth , false /*reportErrors*/ )
3888+ if related == TernaryFalse {
3889+ related = r .isRelatedToEx (s , t , RecursionFlagsBoth , reportErrors , nil /*headMessage*/ , intersectionState )
3890+ }
3891+ } else {
3892+ // In the invariant case we first compare covariantly, and only when that
3893+ // succeeds do we proceed to compare contravariantly. Thus, error elaboration
3894+ // will typically be based on the covariant check.
3895+ related = r .isRelatedToEx (s , t , RecursionFlagsBoth , reportErrors , nil /*headMessage*/ , intersectionState )
3896+ if related != TernaryFalse {
3897+ related &= r .isRelatedToEx (t , s , RecursionFlagsBoth , reportErrors , nil /*headMessage*/ , intersectionState )
3898+ }
38933899 }
38943900 }
38953901 if related == TernaryFalse {
0 commit comments