Skip to content

Commit

Permalink
Merge pull request #15553 from dwijnand/space/sealed-abstracts-redund…
Browse files Browse the repository at this point in the history
…ancy

space: Fix how sealed abstract classes decompose
  • Loading branch information
anatoliykmetyuk authored Jul 8, 2022
2 parents 8765a16 + d353010 commit 18f2c0e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ class SpaceEngine(using Context) extends SpaceLogic {
case tp =>
def getChildren(sym: Symbol): List[Symbol] =
sym.children.flatMap { child =>
if child eq sym then Nil // i3145: sealed trait Baz, val x = new Baz {}, Baz.children returns Baz...
if child eq sym then List(sym) // i3145: sealed trait Baz, val x = new Baz {}, Baz.children returns Baz...
else if tp.classSymbol == defn.TupleClass || tp.classSymbol == defn.NonEmptyTupleClass then
List(child) // TupleN and TupleXXL classes are used for Tuple, but they aren't Tuple's children
else if (child.is(Private) || child.is(Sealed)) && child.isOneOf(AbstractOrTrait) then getChildren(child)
Expand Down
13 changes: 13 additions & 0 deletions tests/pos/i15522.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// scalac: -Werror
sealed trait Coverage
sealed abstract case class Range(min: Double, max: Double) extends Coverage
case object Empty extends Coverage

object Test:
def mkCoverage(min: Double, max: Double): Coverage =
if min < max then new Range(min, max) {} else Empty

def meth(c1: Coverage, c2: Coverage): Coverage = (c1, c2) match
case (Empty, _) => Empty
case (_, Empty) => Empty // was: Unreachable case
case (Range(a1, b1), Range(a2, b2)) => mkCoverage(a1 max a2, b1 min b2)

0 comments on commit 18f2c0e

Please sign in to comment.