From e5b18ebb804453941ce3f8816d3f04a8b880fa7e Mon Sep 17 00:00:00 2001 From: liu fengyun Date: Wed, 11 Apr 2018 23:06:41 +0200 Subject: [PATCH] use ApproximatingTypeMap to simplify exhaustivity check code --- .../tools/dotc/transform/patmat/Space.scala | 24 ++++--------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index 20057a560016..2cb690805a9c 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -605,32 +605,16 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic { * */ def instantiate(tp1: NamedType, tp2: Type)(implicit ctx: Context): Type = { - // expose abstract type references to their bounds or tvars according to variance - class AbstractTypeMap(maximize: Boolean)(implicit ctx: Context) extends TypeMap { - def expose(lo: Type, hi: Type): Type = - if (variance == 0) - newTypeVar(TypeBounds(lo, hi)) - else if (variance == 1) - if (maximize) hi else lo - else - if (maximize) lo else hi + // expose type param references to their bounds according to variance + class AbstractTypeMap(maximize: Boolean)(implicit ctx: Context) extends ApproximatingTypeMap { + variance = if (maximize) 1 else -1 def apply(tp: Type): Type = tp match { case tp: TypeRef if tp.underlying.isInstanceOf[TypeBounds] => val lo = this(tp.info.loBound) val hi = this(tp.info.hiBound) // See tests/patmat/gadt.scala tests/patmat/exhausting.scala tests/patmat/t9657.scala - val exposed = expose(lo, hi) - debug.println(s"$tp exposed to =====> $exposed") - exposed - - case AppliedType(tycon: TypeRef, args) if tycon.underlying.isInstanceOf[TypeBounds] => - val args2 = args.map(this) - val lo = this(tycon.info.loBound).applyIfParameterized(args2) - val hi = this(tycon.info.hiBound).applyIfParameterized(args2) - val exposed = expose(lo, hi) - debug.println(s"$tp exposed to =====> $exposed") - exposed + range(lo, hi) case _ => mapOver(tp)