Skip to content

Commit

Permalink
Fix #12602: All sealed classes can be deecomposed
Browse files Browse the repository at this point in the history
  • Loading branch information
liufengyun committed May 25, 2021
1 parent 9a0182a commit 37f4855
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -659,10 +659,7 @@ class SpaceEngine(using Context) extends SpaceLogic {
case and: AndType => canDecompose(and.tp1) || canDecompose(and.tp2)
case _ =>
val cls = tp.classSymbol
cls.is(Sealed)
&& cls.isOneOf(AbstractOrTrait)
&& !cls.hasAnonymousChild
&& cls.children.nonEmpty
cls.is(Sealed) && !cls.hasAnonymousChild
|| cls.isAllOf(JavaEnumTrait)
|| tp.isRef(defn.BooleanClass)
|| tp.isRef(defn.UnitClass)
Expand Down Expand Up @@ -846,6 +843,9 @@ class SpaceEngine(using Context) extends SpaceLogic {

if (!exhaustivityCheckable(sel)) return

debug.println("checking " + _match.show)
debug.println("selTyp = " + selTyp.show)

val patternSpace = Or(cases.foldLeft(List.empty[Space]) { (acc, x) =>
val space = if (x.guard.isEmpty) project(x.pat) else Empty
debug.println(s"${x.pat.show} ====> ${show(space)}")
Expand Down
2 changes: 2 additions & 0 deletions tests/patmat/i12602.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sealed abstract class Foo[T]
object Foo extends Foo[Nothing]

0 comments on commit 37f4855

Please sign in to comment.