Skip to content

Commit 4f40ef0

Browse files
committed
Handle enums that have multiple parents
1 parent ae37dcc commit 4f40ef0

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -2586,9 +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) =>
2589+
case (tp1: TermRef, tp2: TypeRef) if isEnumValueOrModule(tp1) && !tp1.classSymbols.exists(_.derivesFrom(tp2.classSymbol)) =>
2590+
// Note: enum values may have multiple parents
25902591
true
2591-
case (tp1: TypeRef, tp2: TermRef) if isEnumValueOrModule(tp2) && !tp2.symbol.moduleClass.derivesFrom(tp1.classSymbol) =>
2592+
case (tp1: TypeRef, tp2: TermRef) if isEnumValueOrModule(tp2) && !tp2.classSymbols.exists(_.derivesFrom(tp1.classSymbol)) =>
25922593
true
25932594
case (tp1: Type, tp2: Type) if defn.isTupleType(tp1) =>
25942595
provablyDisjoint(tp1.toNestedPairs, tp2)

tests/patmat/i12475b.scala

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
trait SomeRestriction
2+
3+
enum ADT {
4+
case A
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)