diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index a0eb5139eb07..cf2507aa1724 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -1338,8 +1338,11 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling } } || tryLiftedToThis2 - case _: TypeVar => - recur(tp1, tp2.superType) + case tv: TypeVar => + if tv.isInstantiated then + recur(tp1, tp2.superType) + else + compareAppliedType2(tp2, tv.origin, args2) case tycon2: AnnotatedType if !tycon2.isRefining => recur(tp1, tp2.superType) case tycon2: AppliedType => diff --git a/tests/pos/i12478.scala b/tests/pos/i12478.scala new file mode 100644 index 000000000000..d1e247ae4e68 --- /dev/null +++ b/tests/pos/i12478.scala @@ -0,0 +1,19 @@ +sealed trait Foo[T] + +object Foo: + case class Bar[F[_]](fu: List[F[Unit]]) extends Foo[F[Unit]] + +class Test: + def id1[T1](foo1: Foo[T1]): Foo[T1] = foo1 match + case Foo.Bar(fu) => + Foo.Bar(fu) + + def id2[T2](foo2: Foo[T2]): Foo[T2] = foo2 match + case bar2 @ (_: Foo.Bar[f]) => + val fu2 = bar2.fu + Foo.Bar(fu2) + + def id3[T3](foo3: Foo[T3]): Foo[T3] = foo3 match + case bar3 @ Foo.Bar(_) => + val fu3 = bar3.fu + Foo.Bar(fu3)