Skip to content

Commit 2fa5196

Browse files
committed
Reshuffle nested and/or calls.
Overall goal: Push backtracking deeper into the tree.
1 parent af60377 commit 2fa5196

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,18 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
345345
}
346346
compareRefined
347347
case OrType(tp21, tp22) =>
348+
// Rewrite T1 <: (T211 & T212) | T22 to T1 <: (T211 | T22) and T1 <: (T212 | T22)
349+
// and analogously for T1 <: T21 | (T221 & T222)
350+
tp21 match {
351+
case AndType(tp211, tp212) =>
352+
return isSubType(tp1, OrType(tp211, tp22)) && isSubType(tp1, OrType(tp212, tp22))
353+
case _ =>
354+
}
355+
tp22 match {
356+
case AndType(tp221, tp222) =>
357+
return isSubType(tp1, OrType(tp21, tp221)) && isSubType(tp1, OrType(tp21, tp222))
358+
case _ =>
359+
}
348360
eitherIsSubType(tp1, tp21, tp1, tp22) || fourthTry(tp1, tp2)
349361
case tp2 @ MethodType(_, formals2) =>
350362
def compareMethod = tp1 match {
@@ -447,6 +459,18 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
447459
isNewSubType(tp1.parent, tp2) ||
448460
needsEtaLift(tp2, tp1) && tp2.testLifted(tp1.typeParams, isSubType(tp1, _), Nil)
449461
case AndType(tp11, tp12) =>
462+
// Rewrite (T111 | T112) & T12 <: T2 to (T111 & T12) <: T2 and (T112 | T12) <: T2
463+
// and analogously for T11 & (T121 | T122) & T12 <: T2
464+
tp11 match {
465+
case OrType(tp111, tp112) =>
466+
return isSubType(AndType(tp111, tp12), tp2) && isSubType(AndType(tp112, tp12), tp2)
467+
case _ =>
468+
}
469+
tp12 match {
470+
case OrType(tp121, tp122) =>
471+
return isSubType(AndType(tp11, tp121), tp2) && isSubType(AndType(tp11, tp122), tp2)
472+
case _ =>
473+
}
450474
eitherIsSubType(tp11, tp2, tp12, tp2)
451475
case JavaArrayType(elem1) =>
452476
def compareJavaArray = tp2 match {

0 commit comments

Comments
 (0)