Skip to content

Commit

Permalink
Fix regression in provablyDisjoint (cherry-picked from scala#12786)
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierBlanvillain committed Jun 11, 2021
1 parent af7b341 commit 957de6d
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2492,9 +2492,15 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
def provablyDisjoint(tp1: Type, tp2: Type)(using Context): Boolean = trace(i"provable disjoint $tp1, $tp2", matchTypes) {
// println(s"provablyDisjoint(${tp1.show}, ${tp2.show})")

def isEnumValueOrModule(ref: TermRef): Boolean =
def isEnumValue(ref: TermRef): Boolean =
val sym = ref.termSymbol
sym.isAllOf(EnumCase, butNot=JavaDefined) || sym.is(Module)
sym.isAllOf(EnumCase, butNot=JavaDefined)

def isEnumValueOrModule(ref: TermRef): Boolean =
isEnumValue(ref) || ref.termSymbol.is(Module) || (ref.info match {
case tp: TermRef => isEnumValueOrModule(tp)
case _ => false
})

/** Can we enumerate all instantiations of this type? */
def isClosedSum(tp: Symbol): Boolean =
Expand Down Expand Up @@ -2603,11 +2609,10 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
provablyDisjoint(tp1, gadtBounds(tp2.symbol).hi) || provablyDisjoint(tp1, tp2.superType)
case (tp1: TermRef, tp2: TermRef) if isEnumValueOrModule(tp1) && isEnumValueOrModule(tp2) =>
tp1.termSymbol != tp2.termSymbol
case (tp1: TermRef, tp2: TypeRef) if isEnumValueOrModule(tp1) && !tp1.classSymbols.exists(_.derivesFrom(tp2.classSymbol)) =>
// Note: enum values may have multiple parents
true
case (tp1: TypeRef, tp2: TermRef) if isEnumValueOrModule(tp2) && !tp2.classSymbols.exists(_.derivesFrom(tp1.classSymbol)) =>
true
case (tp1: TermRef, _) if isEnumValue(tp1) =>
false
case (_, tp2: TermRef) if isEnumValue(tp2) =>
false
case (tp1: Type, tp2: Type) if defn.isTupleType(tp1) =>
provablyDisjoint(tp1.toNestedPairs, tp2)
case (tp1: Type, tp2: Type) if defn.isTupleType(tp2) =>
Expand Down

0 comments on commit 957de6d

Please sign in to comment.