Skip to content

Commit a2f0fc1

Browse files
committed
Fix hk comparison between class and range lambda
In a situation like List <: [X] -> <: GenTraversable[X] We have to ask whether the rhs contains the instantiated lhs, not whether it is a supertype.
1 parent bde77d4 commit a2f0fc1

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
124124
pendingSubTypes = new mutable.HashSet[(Type, Type)]
125125
ctx.log(s"!!! deep subtype recursion involving ${tp1.show} <:< ${tp2.show}, constraint = ${state.constraint.show}")
126126
ctx.log(s"!!! constraint = ${constraint.show}")
127-
if (ctx.settings.YnoDeepSubtypes.value) throw new Error("deep subtype")
127+
assert(!ctx.settings.YnoDeepSubtypes.value) //throw new Error("deep subtype")
128128
if (Config.traceDeepSubTypeRecursions && !this.isInstanceOf[ExplainingTypeComparer])
129129
ctx.log(TypeComparer.explained(implicit ctx => ctx.typeComparer.isSubType(tp1, tp2)))
130130
}
@@ -598,7 +598,11 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
598598
other.isInstanceOf[TypeRef] &&
599599
args.length == other.typeParams.length && {
600600
val applied = other.appliedTo(argRefs(rt, args.length))
601-
if (inOrder) isSubType(body, applied) else isSubType(applied, body)
601+
if (inOrder) isSubType(body, applied)
602+
else body match {
603+
case body: TypeBounds => body.contains(applied)
604+
case _ => isSubType(applied, body)
605+
}
602606
}
603607
case _ =>
604608
false
@@ -1233,7 +1237,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
12331237

12341238
/** Show subtype goal that led to an assertion failure */
12351239
def showGoal(tp1: Type, tp2: Type)(implicit ctx: Context) = {
1236-
ctx.println(disambiguated(implicit ctx => s"assertion failure for ${tp1.show} <:< ${tp2.show}, frozen = $frozenConstraint"))
1240+
println(disambiguated(implicit ctx => s"assertion failure for ${tp1.show} <:< ${tp2.show}, frozen = $frozenConstraint"))
12371241
def explainPoly(tp: Type) = tp match {
12381242
case tp: PolyParam => ctx.println(s"polyparam ${tp.show} found in ${tp.binder.show}")
12391243
case tp: TypeRef if tp.symbol.exists => ctx.println(s"typeref ${tp.show} found in ${tp.symbol.owner.show}")
@@ -1323,10 +1327,17 @@ class ExplainingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
13231327

13241328
override def compareHkApply(projection: NamedType, other: Type, inOrder: Boolean) =
13251329
if (projection.name == tpnme.hkApply)
1326-
traceIndented(i"compareHK $projection, $other, $inOrder") {
1330+
traceIndented(i"compareHkApply $projection, $other, $inOrder") {
13271331
super.compareHkApply(projection, other, inOrder)
13281332
}
13291333
else super.compareHkApply(projection, other, inOrder)
13301334

1335+
override def compareHkLambda(rt: RefinedType, other: Type, inOrder: Boolean) =
1336+
if (rt.refinedName == tpnme.hkApply)
1337+
traceIndented(i"compareHkLambda $rt, $other, $inOrder") {
1338+
super.compareHkLambda(rt, other, inOrder)
1339+
}
1340+
else super.compareHkLambda(rt, other, inOrder)
1341+
13311342
override def toString = "Subtype trace:" + { try b.toString finally b.clear() }
13321343
}

tests/pos/hklub0.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object Test {
2+
val a : scala.collection.generic.GenericCompanion[scala.collection.immutable.Seq] = null
3+
val b : scala.collection.generic.GenericCompanion[scala.collection.mutable.Seq] = null
4+
List(a, b) // immutable.this.List.apply[scala.collection.generic.GenericCompanion[Seq]](Test.this.a, Test.this.b)
5+
}

tests/pos/hkrange.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class A {
2+
def f[CC[X] <: Traversable[X]](x: CC[Int]) = ()
3+
4+
f(1 to 5)
5+
}

0 commit comments

Comments
 (0)