Skip to content

Commit 24c0ee6

Browse files
committed
Don't confuse MethodTypes and PolyTypes in type comparer
I assumed the existing tests were already sufficient to avoid confusion before we try a substitution of one for the other, but was wrong in the case where both sides are riddled with errors. Test case (too long/fuzzy to be included in regression tests): case class i0[i1, i4](i4: i1) object i4 { implicit def i4[i1: i0](i4: i1): i1 def i4[i4[_], i4[_], i4[i4]](i4: i1[i4]): i4[i4] = null } class i1 extends i4 { case _ => } val i1 = new i0 { type i1[i4] = i4 with i0[i4] trait i1 extends i4 { type i1[i4] = i1 type i4 = i4#i4 def i4[i4 >: i4](i4: => i4): i4.i4[_ <: i4] = i4 i4(i1, i4: i4) def unapply(i2: i4) = sys.error("") } trait i4 trait throw { val i3: i4 = i4(5, i1: i1, i4: i4) def i3: i4[Int] = i1(null: Any) i3(0, i1()) println(i3 <= i4) } object i1 { implicit def i1(i4: i4): Int def i1[@specialized i4 <: i4[i4]](i1: i4): i4[Int] def i1[@specialized i4, i4 <: i1](i4: i4): i4[i1[i4]] = new i4[i1] { val i1 = (new i2.i1 } }
1 parent 75013f1 commit 24c0ee6

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -527,17 +527,18 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
527527
case _ =>
528528
}
529529
either(recur(tp1, tp21), recur(tp1, tp22)) || fourthTry
530-
case tp2: MethodOrPoly =>
530+
case tp2: MethodType =>
531531
def compareMethod = tp1 match {
532-
case tp1: MethodOrPoly =>
533-
(tp1.signature consistentParams tp2.signature) &&
534-
matchingParams(tp1, tp2) &&
535-
(!tp2.isImplicitMethod || tp1.isImplicitMethod) &&
536-
isSubType(tp1.resultType, tp2.resultType.subst(tp2, tp1))
537-
case _ =>
538-
false
532+
case tp1: MethodType => compareMethodOrPoly(tp1, tp2)
533+
case _ => false
539534
}
540535
compareMethod
536+
case tp2: PolyType =>
537+
def comparePoly = tp1 match {
538+
case tp1: PolyType => compareMethodOrPoly(tp1, tp2)
539+
case _ => false
540+
}
541+
comparePoly
541542
case tp2 @ ExprType(restpe2) =>
542543
def compareExpr = tp1 match {
543544
// We allow ()T to be a subtype of => T.
@@ -573,6 +574,12 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
573574
fourthTry
574575
}
575576

577+
def compareMethodOrPoly(tp1: MethodOrPoly, tp2: MethodOrPoly) =
578+
(tp1.signature consistentParams tp2.signature) &&
579+
matchingParams(tp1, tp2) &&
580+
(!tp2.isImplicitMethod || tp1.isImplicitMethod) &&
581+
isSubType(tp1.resultType, tp2.resultType.subst(tp2, tp1))
582+
576583
def fourthTry: Boolean = tp1 match {
577584
case tp1: TypeRef =>
578585
tp1.info match {

0 commit comments

Comments
 (0)