From 37f48555ca670108b81b66c96aca5fd24e56b6b7 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Tue, 25 May 2021 19:59:04 +0200 Subject: [PATCH] Fix #12602: All sealed classes can be deecomposed --- .../src/dotty/tools/dotc/transform/patmat/Space.scala | 8 ++++---- tests/patmat/i12602.scala | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 tests/patmat/i12602.scala diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index 706071388111..65e72d2d5274 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -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) @@ -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)}") diff --git a/tests/patmat/i12602.scala b/tests/patmat/i12602.scala new file mode 100644 index 000000000000..8ea53147455d --- /dev/null +++ b/tests/patmat/i12602.scala @@ -0,0 +1,2 @@ +sealed abstract class Foo[T] +object Foo extends Foo[Nothing]