Skip to content

Commit 957de6d

Browse files
Fix regression in provablyDisjoint (cherry-picked from #12786)
1 parent af7b341 commit 957de6d

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2492,9 +2492,15 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
24922492
def provablyDisjoint(tp1: Type, tp2: Type)(using Context): Boolean = trace(i"provable disjoint $tp1, $tp2", matchTypes) {
24932493
// println(s"provablyDisjoint(${tp1.show}, ${tp2.show})")
24942494

2495-
def isEnumValueOrModule(ref: TermRef): Boolean =
2495+
def isEnumValue(ref: TermRef): Boolean =
24962496
val sym = ref.termSymbol
2497-
sym.isAllOf(EnumCase, butNot=JavaDefined) || sym.is(Module)
2497+
sym.isAllOf(EnumCase, butNot=JavaDefined)
2498+
2499+
def isEnumValueOrModule(ref: TermRef): Boolean =
2500+
isEnumValue(ref) || ref.termSymbol.is(Module) || (ref.info match {
2501+
case tp: TermRef => isEnumValueOrModule(tp)
2502+
case _ => false
2503+
})
24982504

24992505
/** Can we enumerate all instantiations of this type? */
25002506
def isClosedSum(tp: Symbol): Boolean =
@@ -2603,11 +2609,10 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
26032609
provablyDisjoint(tp1, gadtBounds(tp2.symbol).hi) || provablyDisjoint(tp1, tp2.superType)
26042610
case (tp1: TermRef, tp2: TermRef) if isEnumValueOrModule(tp1) && isEnumValueOrModule(tp2) =>
26052611
tp1.termSymbol != tp2.termSymbol
2606-
case (tp1: TermRef, tp2: TypeRef) if isEnumValueOrModule(tp1) && !tp1.classSymbols.exists(_.derivesFrom(tp2.classSymbol)) =>
2607-
// Note: enum values may have multiple parents
2608-
true
2609-
case (tp1: TypeRef, tp2: TermRef) if isEnumValueOrModule(tp2) && !tp2.classSymbols.exists(_.derivesFrom(tp1.classSymbol)) =>
2610-
true
2612+
case (tp1: TermRef, _) if isEnumValue(tp1) =>
2613+
false
2614+
case (_, tp2: TermRef) if isEnumValue(tp2) =>
2615+
false
26112616
case (tp1: Type, tp2: Type) if defn.isTupleType(tp1) =>
26122617
provablyDisjoint(tp1.toNestedPairs, tp2)
26132618
case (tp1: Type, tp2: Type) if defn.isTupleType(tp2) =>

0 commit comments

Comments
 (0)