Skip to content

Commit 64e8185

Browse files
committed
Generalize comparisons from PolyTypes to TypeLambdas
1 parent a5ea97a commit 64e8185

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,9 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
428428
compareRec
429429
case tp2 @ HKApply(tycon2, args2) =>
430430
compareHkApply2(tp1, tp2, tycon2, args2)
431-
case tp2 @ PolyType(tparams2, body2) =>/*###*/
432-
def compareHkLambda: Boolean = tp1.stripTypeVar match {
433-
case tp1 @ PolyType(tparams1, body1) =>/*###*/
431+
case tp2: TypeLambda =>
432+
def compareTypeLambda: Boolean = tp1.stripTypeVar match {
433+
case tp1: TypeLambda if tp1.isInstanceOf[PolyType] == tp2.isInstanceOf[PolyType] =>
434434
/* Don't compare bounds of lambdas under language:Scala2, or t2994 will fail
435435
* The issue is that, logically, bounds should compare contravariantly,
436436
* but that would invalidate a pattern exploited in t2994:
@@ -446,15 +446,15 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
446446
*/
447447
def boundsOK =
448448
ctx.scala2Mode ||
449-
tparams1.corresponds(tparams2)((tparam1, tparam2) =>
449+
tp1.typeParams.corresponds(tp2.typeParams)((tparam1, tparam2) =>
450450
isSubType(tparam2.paramInfo.subst(tp2, tp1), tparam1.paramInfo))
451451
val saved = comparedTypeLambdas
452452
comparedTypeLambdas += tp1
453453
comparedTypeLambdas += tp2
454454
try
455-
variancesConform(tparams1, tparams2) &&
455+
variancesConform(tp1.typeParams, tp2.typeParams) &&
456456
boundsOK &&
457-
isSubType(body1, body2.subst(tp2, tp1))
457+
isSubType(tp1.resType, tp2.resType.subst(tp2, tp1))
458458
finally comparedTypeLambdas = saved
459459
case _ =>
460460
if (!tp1.isHK) {
@@ -466,7 +466,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
466466
}
467467
fourthTry(tp1, tp2)
468468
}
469-
compareHkLambda
469+
compareTypeLambda
470470
case OrType(tp21, tp22) =>
471471
// Rewrite T1 <: (T211 & T212) | T22 to T1 <: (T211 | T22) and T1 <: (T212 | T22)
472472
// and analogously for T1 <: T21 | (T221 & T222)

0 commit comments

Comments
 (0)