Skip to content

Commit 2164c42

Browse files
authored
Merge pull request #3713 from dotty-staging/fix-#2989
Add missing case to TypeComparer
2 parents e1d2d56 + 2a285cd commit 2164c42

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ object desugar {
10651065
AppliedTypeTree(ref(seqType), t),
10661066
New(ref(defn.RepeatedAnnotType), Nil :: Nil))
10671067
} else {
1068-
assert(ctx.mode.isExpr || ctx.reporter.hasErrors, ctx.mode)
1068+
assert(ctx.mode.isExpr || ctx.reporter.hasErrors || ctx.mode.is(Mode.Interactive), ctx.mode)
10691069
Select(t, op.name)
10701070
}
10711071
case PrefixOp(op, t) =>

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,17 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
475475
isSubType(tp1.resType, tp2.resType.subst(tp2, tp1))
476476
finally comparedTypeLambdas = saved
477477
case _ =>
478-
if (!tp1.isHK) {
479-
tp2 match {
480-
case EtaExpansion(tycon2) if tycon2.symbol.isClass =>
481-
return isSubType(tp1, tycon2)
482-
case _ =>
483-
}
478+
if (tp1.isHK) {
479+
val tparams1 = tp1.typeParams
480+
return isSubType(
481+
HKTypeLambda.fromParams(tparams1, tp1.appliedTo(tparams1.map(_.paramRef))),
482+
tp2
483+
)
484+
}
485+
else tp2 match {
486+
case EtaExpansion(tycon2) if tycon2.symbol.isClass =>
487+
return isSubType(tp1, tycon2)
488+
case _ =>
484489
}
485490
fourthTry(tp1, tp2)
486491
}

tests/pos/i2989.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Foo[+X[_]] {
2+
// OK
3+
def foo1[Y[_]](right: Foo[Y]): Foo[Y] = right
4+
// OK
5+
def foo2[Y[_]](right: Foo[[T] => Y[T]]): Foo[Y] = right
6+
// OK
7+
def foo3[Y[_]](right: Foo[[T] => Y[T]]): Foo[[T] => Y[T]] = right
8+
// Error:
9+
// found: Foo[Y](right)
10+
// required: Foo[Y]
11+
def foo4[Y[_]](right: Foo[Y]): Foo[[T] => Y[T]] = right
12+
}

tests/pos/i3658.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
object App {
2+
def main(args: Array[String]): Unit = {
3+
trait ModuleSig {
4+
type F[_]
5+
type Type = F
6+
7+
def subst[F[_[_]]](fa: F[List]): F[Type]
8+
}
9+
val Module: ModuleSig = new ModuleSig {
10+
type F[+A] = List[A]
11+
12+
def subst[FF[_[_]]](fa: FF[List]): FF[Type] = fa
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)