Skip to content

Commit 19c945b

Browse files
committed
Fix provablyDisjoint handling enum constants with mixins
1 parent 71b0aea commit 19c945b

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

Diff for: compiler/src/dotty/tools/dotc/core/TypeComparer.scala

+4-3
Original file line numberDiff line numberDiff line change
@@ -3196,9 +3196,10 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
31963196
cls.is(Sealed) && !cls.hasAnonymousChild
31973197

31983198
def decompose(cls: Symbol): List[Symbol] =
3199-
cls.children.map { child =>
3200-
if child.isTerm then child.info.classSymbol
3201-
else child
3199+
cls.children.flatMap { child =>
3200+
if child.isTerm then
3201+
child.info.classSymbols // allow enum vals to be decomposed to their enum class (then filtered out) and any mixins
3202+
else child :: Nil
32023203
}.filter(child => child.exists && child != cls)
32033204

32043205
def eitherDerivesFromOther(cls1: Symbol, cls2: Symbol): Boolean =

Diff for: tests/warn/i21860.scala

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
trait Figure
2+
sealed trait Corners { self: Figure => }
3+
4+
enum Shape extends Figure:
5+
case Triangle extends Shape with Corners
6+
case Square extends Shape with Corners
7+
case Circle extends Shape
8+
case Ellipsis extends Shape
9+
10+
def hasCorners(s: Shape): Boolean = s match
11+
case hasCorners: Corners => true // <--- reported as `Unreachable case`
12+
case _ => false
13+
14+
class Test:
15+
def test(): Unit =
16+
println(hasCorners(Shape.Circle))

Diff for: tests/warn/i21860.unenum.scala

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
trait Figure
2+
sealed trait Corners { self: Figure => }
3+
4+
sealed abstract class Shape extends Figure
5+
object Shape:
6+
case object Triange extends Shape with Corners
7+
case object Square extends Shape with Corners
8+
case object Circle extends Shape
9+
case object Ellipsis extends Shape
10+
11+
def hasCorners(s: Shape): Boolean = s match
12+
case hasCorners: Corners => true // <--- reported as `Unreachable case`
13+
case _ => false
14+
15+
class Test:
16+
def test(): Unit =
17+
println(hasCorners(Shape.Circle))

0 commit comments

Comments
 (0)