Skip to content

Commit a738925

Browse files
committed
Fix #12546: Handle enum or object in provablyDisjoint
A enum or object is provably disjoint with a class A if the module class does not derive from A.
1 parent d2dd083 commit a738925

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2586,6 +2586,10 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
25862586
provablyDisjoint(tp1, gadtBounds(tp2.symbol).hi) || provablyDisjoint(tp1, tp2.superType)
25872587
case (tp1: TermRef, tp2: TermRef) if isEnumValueOrModule(tp1) && isEnumValueOrModule(tp2) =>
25882588
tp1.termSymbol != tp2.termSymbol
2589+
case (tp1: TermRef, tp2: TypeRef) if isEnumValueOrModule(tp1) && !tp1.symbol.moduleClass.derivesFrom(tp2.classSymbol) =>
2590+
true
2591+
case (tp1: TypeRef, tp2: TermRef) if isEnumValueOrModule(tp2) && !tp2.symbol.moduleClass.derivesFrom(tp1.classSymbol) =>
2592+
true
25892593
case (tp1: Type, tp2: Type) if defn.isTupleType(tp1) =>
25902594
provablyDisjoint(tp1.toNestedPairs, tp2)
25912595
case (tp1: Type, tp2: Type) if defn.isTupleType(tp2) =>

tests/patmat/i12546.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
trait SomeRestriction
2+
3+
enum ADT {
4+
case A extends ADT
5+
case B extends ADT with SomeRestriction
6+
}
7+
8+
object MinimalExample {
9+
val b: ADT & SomeRestriction = ADT.B
10+
11+
b match {
12+
case ADT.B => ???
13+
}
14+
}

0 commit comments

Comments
 (0)