Skip to content

Commit a6caf1c

Browse files
committed
Generalize compareHkApply to types other than PolyParams
This seems to be required to make Typer compile, and it is logical that we should do this. We still need to study how it fits in the general context. Also, it required neg test to be fixed. With the change, the error is now reported earlier.
1 parent 1844c1d commit a6caf1c

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,8 +656,19 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
656656
subtyping.println(i"type params = $hkTypeParams")
657657
if (inOrder) unifyWith(other)
658658
else testLifted(other, app, hkTypeParams, unifyWith)
659-
case _ =>
660-
false
659+
660+
case tp => // TODO check this is the right way to do it.
661+
other.typeConstructor.widen match {
662+
case tycon: TypeRef =>
663+
tycon.isEtaExpandable &&
664+
tycon.typeParams.length == tp.typeParams.length &&
665+
!ctx.mode.is(Mode.TypevarsMissContext) && {
666+
val app1 = EtaExpansion(tycon).appliedTo(app.argInfos)
667+
if (inOrder) isSubType(app1, other) else isSubType(other, app1)
668+
}
669+
case _ =>
670+
false
671+
}
661672
}
662673
}
663674
Config.newHK && app.isHKApply && !other.isHKApply && {

tests/neg/i1240a.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ abstract class A {
1010
class B extends A {
1111
type C[X] = List[X]
1212
override def give[X] = Nil
13-
override def foo[B](x: C[B]): C[B] = {println("B.C"); x} // error: merge error during erasure
13+
override def foo[B](x: C[B]): C[B] = {println("B.C"); x}
1414
val a: A = this
15-
a.foo(a.give[Int]) // what method should be called here in runtime?
15+
a.foo(a.give[Int]) // what method should be called here in runtime? // error: ambiguous
1616
}
1717

0 commit comments

Comments
 (0)