@@ -2526,17 +2526,6 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
2526
2526
case _ => false
2527
2527
})
2528
2528
2529
- /** Can we enumerate all instantiations of this type? */
2530
- def isClosedSum (tp : Symbol ): Boolean =
2531
- tp.is(Sealed ) && tp.isOneOf(AbstractOrTrait ) && ! tp.hasAnonymousChild
2532
-
2533
- /** Splits a closed type into a disjunction of smaller types.
2534
- * It should hold that `tp` and `decompose(tp).reduce(_ or _)`
2535
- * denote the same set of values.
2536
- */
2537
- def decompose (sym : Symbol , tp : Type ): List [Type ] =
2538
- sym.children.map(x => refineUsingParent(tp, x)).filter(_.exists)
2539
-
2540
2529
def fullyInstantiated (tp : Type ): Boolean = new TypeAccumulator [Boolean ] {
2541
2530
override def apply (x : Boolean , t : Type ) =
2542
2531
x && {
@@ -2558,6 +2547,10 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
2558
2547
case (tp1 : TypeRef , tp2 : TypeRef ) if tp1.symbol.isClass && tp2.symbol.isClass =>
2559
2548
val cls1 = tp1.classSymbol
2560
2549
val cls2 = tp2.classSymbol
2550
+ def isDecomposable (tp : Symbol ): Boolean =
2551
+ tp.is(Sealed ) && ! tp.hasAnonymousChild
2552
+ def decompose (sym : Symbol , tp : Type ): List [Type ] =
2553
+ sym.children.map(x => refineUsingParent(tp, x)).filter(_.exists)
2561
2554
if (cls1.derivesFrom(cls2) || cls2.derivesFrom(cls1))
2562
2555
false
2563
2556
else
@@ -2570,9 +2563,13 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
2570
2563
// subtype, so they must be unrelated by single inheritance
2571
2564
// of classes.
2572
2565
true
2573
- else if (isClosedSum(cls1))
2566
+ else if (isDecomposable(cls1))
2567
+ // At this point, !cls1.derivesFrom(cls2): we know that direct
2568
+ // instantiations of `cls1` (terms of the form `new cls1`) are not
2569
+ // of type `tp2`. Therefore, we can safely decompose `cls1` using
2570
+ // `.children`, even if `cls1` is non abstract.
2574
2571
decompose(cls1, tp1).forall(x => provablyDisjoint(x, tp2))
2575
- else if (isClosedSum (cls2))
2572
+ else if (isDecomposable (cls2))
2576
2573
decompose(cls2, tp2).forall(x => provablyDisjoint(x, tp1))
2577
2574
else
2578
2575
false
0 commit comments