File tree Expand file tree Collapse file tree 2 files changed +27
-4
lines changed
compiler/src/dotty/tools/dotc/core Expand file tree Collapse file tree 2 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -579,10 +579,15 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
579
579
val saved = comparedTypeLambdas
580
580
comparedTypeLambdas += tp1
581
581
comparedTypeLambdas += tp2
582
- try
583
- variancesConform(tp1.typeParams, tp2.typeParams) &&
584
- boundsOK &&
585
- isSubType(tp1.resType, tp2.resType.subst(tp2, tp1))
582
+ val variancesOK =
583
+ variancesConform(tp1.typeParams, tp2.typeParams)
584
+ || { // if tp1 is of the form [X] =>> C[X] where `C` is co- or contra-variant
585
+ // assume the variance of `C` for `tp1` instead. Fixes #7648.
586
+ tp1 match
587
+ case EtaExpansion (tycon1) => variancesConform(tycon1.typeParams, tp2.typeParams)
588
+ case _ => false
589
+ }
590
+ try variancesOK && boundsOK && isSubType(tp1.resType, tp2.resType.subst(tp2, tp1))
586
591
finally comparedTypeLambdas = saved
587
592
case _ =>
588
593
val tparams1 = tp1.typeParams
Original file line number Diff line number Diff line change
1
+ package i7648
2
+
3
+ class IO [+ A ]
4
+
5
+ trait Functor [F [_]]
6
+ trait Monad [F [_]] extends Functor [F ]
7
+
8
+ class Stream [+ F [_], + A ] {
9
+ def take [F1 [x] >: F [x]](n : Int )(implicit f : Functor [F1 ]): Stream [F1 , A ] = {
10
+ this
11
+ }
12
+ }
13
+
14
+ object Test with
15
+
16
+ implicit val ioMonad : Monad [IO ] = null
17
+
18
+ val x = new Stream [IO , Int ].take[IO ](10 )
You can’t perform that action at this time.
0 commit comments