Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix provablyDisjoint handling enum constants with mixins #21876

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3196,9 +3196,10 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
cls.is(Sealed) && !cls.hasAnonymousChild

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

def eitherDerivesFromOther(cls1: Symbol, cls2: Symbol): Boolean =
Expand Down
16 changes: 16 additions & 0 deletions tests/warn/i21860.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
trait Figure
sealed trait Corners { self: Figure => }

enum Shape extends Figure:
case Triangle extends Shape with Corners
case Square extends Shape with Corners
case Circle extends Shape
case Ellipsis extends Shape

def hasCorners(s: Shape): Boolean = s match
case hasCorners: Corners => true // <--- reported as `Unreachable case`
case _ => false

class Test:
def test(): Unit =
println(hasCorners(Shape.Circle))
17 changes: 17 additions & 0 deletions tests/warn/i21860.unenum.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
trait Figure
sealed trait Corners { self: Figure => }

sealed abstract class Shape extends Figure
object Shape:
case object Triange extends Shape with Corners
case object Square extends Shape with Corners
case object Circle extends Shape
case object Ellipsis extends Shape

def hasCorners(s: Shape): Boolean = s match
case hasCorners: Corners => true // <--- reported as `Unreachable case`
case _ => false

class Test:
def test(): Unit =
println(hasCorners(Shape.Circle))
Loading