Skip to content

Commit 61d4149

Browse files
committed
use ApproximatingTypeMap to simplify exhaustivity check code
1 parent 4058393 commit 61d4149

File tree

1 file changed

+3
-19
lines changed
  • compiler/src/dotty/tools/dotc/transform/patmat

1 file changed

+3
-19
lines changed

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -606,31 +606,15 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
606606
*/
607607
def instantiate(tp1: NamedType, tp2: Type)(implicit ctx: Context): Type = {
608608
// expose abstract type references to their bounds or tvars according to variance
609-
class AbstractTypeMap(maximize: Boolean)(implicit ctx: Context) extends TypeMap {
610-
def expose(lo: Type, hi: Type): Type =
611-
if (variance == 0)
612-
newTypeVar(TypeBounds(lo, hi))
613-
else if (variance == 1)
614-
if (maximize) hi else lo
615-
else
616-
if (maximize) lo else hi
609+
class AbstractTypeMap(maximize: Boolean)(implicit ctx: Context) extends ApproximatingTypeMap {
610+
variance = if (maximize) 1 else -1
617611

618612
def apply(tp: Type): Type = tp match {
619613
case tp: TypeRef if tp.underlying.isInstanceOf[TypeBounds] =>
620614
val lo = this(tp.info.loBound)
621615
val hi = this(tp.info.hiBound)
622616
// See tests/patmat/gadt.scala tests/patmat/exhausting.scala tests/patmat/t9657.scala
623-
val exposed = expose(lo, hi)
624-
debug.println(s"$tp exposed to =====> $exposed")
625-
exposed
626-
627-
case AppliedType(tycon: TypeRef, args) if tycon.underlying.isInstanceOf[TypeBounds] =>
628-
val args2 = args.map(this)
629-
val lo = this(tycon.info.loBound).applyIfParameterized(args2)
630-
val hi = this(tycon.info.hiBound).applyIfParameterized(args2)
631-
val exposed = expose(lo, hi)
632-
debug.println(s"$tp exposed to =====> $exposed")
633-
exposed
617+
range(lo, hi)
634618

635619
case _ =>
636620
mapOver(tp)

0 commit comments

Comments
 (0)