File tree 2 files changed +19
-0
lines changed
compiler/src/dotty/tools/dotc/transform/patmat
2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -443,6 +443,8 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
443
443
Typ (ConstantType (Constant (true )), true ),
444
444
Typ (ConstantType (Constant (false )), true )
445
445
)
446
+ case tp if tp.isRef(defn.UnitClass ) =>
447
+ Typ (ConstantType (Constant (())), true ) :: Nil
446
448
case tp if tp.classSymbol.is(Enum ) =>
447
449
children.map(sym => Typ (sym.termRef, true ))
448
450
case tp =>
@@ -708,6 +710,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
708
710
canDecompose(and.tp1) || canDecompose(and.tp2)
709
711
}) ||
710
712
tp.isRef(defn.BooleanClass ) ||
713
+ tp.isRef(defn.UnitClass ) ||
711
714
tp.classSymbol.is(allOf(Enum , Sealed )) // Enum value doesn't have Sealed flag
712
715
713
716
debug.println(s " decomposable: ${tp.show} = $res" )
Original file line number Diff line number Diff line change
1
+ sealed abstract class Maybe [A ]
2
+ final case class Just [A ](a : A ) extends Maybe [A ]
3
+ class Empty [A ] extends Maybe [A ]
4
+ object Empty {
5
+ def apply [A ](): Maybe [A ] = new Empty [A ]
6
+ def unapply [A ](e : Empty [A ]): Some [Unit ] = Some (())
7
+ }
8
+
9
+ object Test {
10
+ val a : Maybe [Int ] = Just (2 )
11
+ def main (args : Array [String ]): Unit = a match {
12
+ case Just (_) =>
13
+ // case Empty(_) => // ok
14
+ case Empty (()) => // match may not be exhaustive. It would fail on: Empty(_)
15
+ }
16
+ }
You can’t perform that action at this time.
0 commit comments