Skip to content

Commit 78f9951

Browse files
Fix #11973: Bail out on EnumValues
1 parent e48a268 commit 78f9951

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

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

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

2478-
def isEnumValueOrModule(ref: TermRef): Boolean =
2478+
def isEnumValue(ref: TermRef): Boolean =
24792479
val sym = ref.termSymbol
2480-
sym.isAllOf(EnumCase, butNot=JavaDefined) || sym.is(Module)
2480+
sym.isAllOf(EnumCase, butNot=JavaDefined)
2481+
2482+
def isEnumValueOrModule(ref: TermRef): Boolean =
2483+
isEnumValue(ref) || ref.termSymbol.is(Module)
24812484

24822485
/** Can we enumerate all instantiations of this type? */
24832486
def isClosedSum(tp: Symbol): Boolean =
@@ -2586,6 +2589,10 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
25862589
provablyDisjoint(tp1, gadtBounds(tp2.symbol).hi) || provablyDisjoint(tp1, tp2.superType)
25872590
case (tp1: TermRef, tp2: TermRef) if isEnumValueOrModule(tp1) && isEnumValueOrModule(tp2) =>
25882591
tp1.termSymbol != tp2.termSymbol
2592+
case (tp1: TermRef, _) if isEnumValue(tp1) =>
2593+
false
2594+
case (_, tp2: TermRef) if isEnumValue(tp2) =>
2595+
false
25892596
case (tp1: Type, tp2: Type) if defn.isTupleType(tp1) =>
25902597
provablyDisjoint(tp1.toNestedPairs, tp2)
25912598
case (tp1: Type, tp2: Type) if defn.isTupleType(tp2) =>

tests/pos/11973.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
enum E:
2+
case C
3+
4+
trait T
5+
6+
def f(x: E | T): Unit = x match {
7+
case e: E => ()
8+
case t: T => ()
9+
}

0 commit comments

Comments
 (0)