Skip to content

Commit 3601b34

Browse files
author
Adriaan Moors
committed
exhaust unit: consider Unit as sealed
one of the most boring sealed types imaginable, but a sealed type all the same
1 parent 4da9560 commit 3601b34

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2350,16 +2350,19 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
23502350

23512351
// exhaustivity
23522352

2353-
// make sure it's not a primitive, else (5: Byte) match { case 5 => ... } sees no Byte
2354-
// TODO: domain of feasibly enumerable built-in types (enums, char?)
2353+
// TODO: domain of other feasibly enumerable built-in types (char?)
23552354
def enumerateSubtypes(tp: Type): Option[List[Type]] =
23562355
tp.typeSymbol match {
2356+
// TODO case _ if tp.isTupleType => // recurse into component types?
2357+
case UnitClass =>
2358+
Some(List(UnitClass.tpe))
23572359
case BooleanClass =>
23582360
// patmatDebug("enum bool "+ tp)
23592361
Some(List(ConstantType(Constant(true)), ConstantType(Constant(false))))
23602362
// TODO case _ if tp.isTupleType => // recurse into component types
23612363
case modSym: ModuleClassSymbol =>
23622364
Some(List(tp))
2365+
// make sure it's not a primitive, else (5: Byte) match { case 5 => ... } sees no Byte
23632366
case sym if !sym.isSealed || isPrimitiveValueClass(sym) =>
23642367
// patmatDebug("enum unsealed "+ (tp, sym, sym.isSealed, isPrimitiveValueClass(sym)))
23652368
None

0 commit comments

Comments
 (0)