Skip to content

Commit

Permalink
Fix scala#11973: Bail out on EnumValues
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierBlanvillain committed May 28, 2021
1 parent e48a268 commit 78f9951
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
11 changes: 9 additions & 2 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2475,9 +2475,12 @@ 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)

/** Can we enumerate all instantiations of this type? */
def isClosedSum(tp: Symbol): Boolean =
Expand Down Expand Up @@ -2586,6 +2589,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, _) 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
9 changes: 9 additions & 0 deletions tests/pos/11973.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
enum E:
case C

trait T

def f(x: E | T): Unit = x match {
case e: E => ()
case t: T => ()
}

0 comments on commit 78f9951

Please sign in to comment.