Skip to content

Commit 965021f

Browse files
committed
Fix scala#2989: HK type Y not considered a subtype of [T] => Y[T]
Slightly relax the conditions under which we eta-reduce to account for this case.
1 parent 9de3905 commit 965021f

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -475,14 +475,12 @@ 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+
tp2 match {
479+
case EtaExpansion(tycon2) if (!tp1.isHK && tycon2.symbol.isClass) || tp1.isDirectRef(tycon2.symbol) =>
480+
isSubType(tp1, tycon2)
481+
case _ =>
482+
fourthTry(tp1, tp2)
484483
}
485-
fourthTry(tp1, tp2)
486484
}
487485
compareTypeLambda
488486
case OrType(tp21, tp22) =>

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+
}

0 commit comments

Comments
 (0)