File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
compiler/src/dotty/tools/dotc/transform/patmat Expand file tree Collapse file tree 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 {
443443 Typ (ConstantType (Constant (true )), true ),
444444 Typ (ConstantType (Constant (false )), true )
445445 )
446+ case tp if tp.isRef(defn.UnitClass ) =>
447+ Typ (ConstantType (Constant (())), true ) :: Nil
446448 case tp if tp.classSymbol.is(Enum ) =>
447449 children.map(sym => Typ (sym.termRef, true ))
448450 case tp =>
@@ -708,6 +710,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
708710 canDecompose(and.tp1) || canDecompose(and.tp2)
709711 }) ||
710712 tp.isRef(defn.BooleanClass ) ||
713+ tp.isRef(defn.UnitClass ) ||
711714 tp.classSymbol.is(allOf(Enum , Sealed )) // Enum value doesn't have Sealed flag
712715
713716 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