Skip to content

Ignore private/sealed abstract class/traits #14599

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

Merged
merged 2 commits into from
Mar 2, 2022
Merged
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
10 changes: 9 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,15 @@ class SpaceEngine(using Context) extends SpaceLogic {
case tp if tp.classSymbol.isAllOf(JavaEnumTrait) =>
tp.classSymbol.children.map(sym => Typ(sym.termRef, true))
case tp =>
val children = tp.classSymbol.children
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...
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)
else List(child)
}
val children = getChildren(tp.classSymbol)
debug.println(s"candidates for ${tp.show} : [${children.map(_.show).mkString(", ")}]")

val parts = children.map { sym =>
Expand Down
10 changes: 10 additions & 0 deletions tests/patmat/i14579.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
trait A {
sealed abstract class X
private class X1 extends X with X2 { }
private trait X2 extends X
sealed trait X3 extends X

def f(x: X) = x match {
case _: X1 => 0
}
}
1 change: 0 additions & 1 deletion tests/patmat/patmatexhaust.check
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
53: Pattern Match Exhaustivity: _: Gp
59: Pattern Match Exhaustivity: Nil
75: Pattern Match Exhaustivity: _: B
87: Pattern Match Exhaustivity: _: C1
100: Pattern Match Exhaustivity: _: C1
114: Pattern Match Exhaustivity: D1, D2()
126: Pattern Match Exhaustivity: _: C1
2 changes: 1 addition & 1 deletion tests/patmat/patmatexhaust.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class TestSealedExhaustive { // compile only
case class C3() extends C
case object C4 extends C

def ma10(x: C) = x match { // treat abstract sealed C1 is as inhabited.
def ma10(x: C) = x match { // exhaustive: abstract sealed C1 is dead end.
case C3() => true
case C2 | C4 => true
}
Expand Down