From 176d677258051fd1eef1d1bf26575919cab03530 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 10 Dec 2014 18:53:45 +0100 Subject: Converted some TypeBounds pattern matches to TypeAlias matches. Replace all case TypeBounds(lo, hi) if lo eq hi => patterns with case TypeAlias(alias) => --- src/dotty/tools/dotc/core/TypeApplications.scala | 6 +++--- src/dotty/tools/dotc/core/TypeComparer.scala | 4 ++-- src/dotty/tools/dotc/core/TypeOps.scala | 5 +++-- src/dotty/tools/dotc/core/Types.scala | 13 +++++-------- 4 files changed, 13 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala index d00b018c8..c51092429 100644 --- a/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/src/dotty/tools/dotc/core/TypeApplications.scala @@ -62,7 +62,7 @@ class TypeApplications(val self: Type) extends AnyVal { case tp: RefinedType => val tparams = tp.parent.typeParams tp.refinedInfo match { - case TypeBounds(lo, hi) if lo eq hi => tparams.filterNot(_.name == tp.refinedName) + case rinfo: TypeAlias => tparams.filterNot(_.name == tp.refinedName) case _ => tparams } case tp: SingletonType => @@ -353,9 +353,9 @@ class TypeApplications(val self: Type) extends AnyVal { * for a contravariant type-parameter becomes L. */ final def argInfo(tparam: Symbol, interpolate: Boolean = true)(implicit ctx: Context): Type = self match { + case self: TypeAlias => self.alias case TypeBounds(lo, hi) => - if (lo eq hi) hi - else if (interpolate) { + if (interpolate) { val v = tparam.variance if (v > 0 && (lo isRef defn.NothingClass)) hi else if (v < 0 && (hi isRef defn.AnyClass)) lo diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala index 2140f9bfe..2742d77f2 100644 --- a/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/src/dotty/tools/dotc/core/TypeComparer.scala @@ -668,8 +668,8 @@ class TypeComparer(initctx: Context) extends DotClass { { // special case for situations like: // foo <: C { type T = foo.T } tp2.refinedInfo match { - case TypeBounds(lo, hi) if lo eq hi => - !ctx.phase.erasedTypes && (tp1r select name) =:= lo + case rinfo: TypeAlias => + !ctx.phase.erasedTypes && (tp1r select name) =:= rinfo.alias case _ => false } }) diff --git a/src/dotty/tools/dotc/core/TypeOps.scala b/src/dotty/tools/dotc/core/TypeOps.scala index 7b76feb4d..8bda49c94 100644 --- a/src/dotty/tools/dotc/core/TypeOps.scala +++ b/src/dotty/tools/dotc/core/TypeOps.scala @@ -142,9 +142,10 @@ trait TypeOps { this: Context => def needsChecking(tp: Type, isPart: Boolean): Boolean = tp match { case tp: TypeRef => tp.info match { + case TypeAlias(alias) => + needsChecking(alias, isPart) case TypeBounds(lo, hi) => - if (lo eq hi) needsChecking(hi, isPart) - else isPart || tp.controlled(isVolatile(hi)) + isPart || tp.controlled(isVolatile(hi)) case _ => false } case tp: RefinedType => diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index b67aac1fe..6e224d6f6 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -104,8 +104,8 @@ object Types { */ def isRef(sym: Symbol)(implicit ctx: Context): Boolean = stripTypeVar match { case this1: TypeRef => - this1.info match { // see comment in Namers/typeDefSig - case TypeBounds(lo, hi) if lo eq hi => hi.isRef(sym) + this1.info match { // see comment in Namer#typeDefSig + case TypeAlias(tp) => tp.isRef(sym) case _ => this1.symbol eq sym } case this1: RefinedType => @@ -193,10 +193,7 @@ object Types { } /** Is this an alias TypeBounds? */ - def isAlias: Boolean = this match { - case TypeBounds(lo, hi) => lo eq hi - case _ => false - } + def isAlias: Boolean = this.isInstanceOf[TypeAlias] /** Is this type a transitive refinement of the given type? * This is true if the type consists of 0 or more refinements or other @@ -759,7 +756,7 @@ object Types { case pre: RefinedType => if (pre.refinedName ne name) loop(pre.parent) else this.member(name).info match { - case TypeBounds(lo, hi) if (lo eq hi) && !dependsOnRefinedThis(hi) => hi + case TypeAlias(tp) if !dependsOnRefinedThis(tp) => tp case _ => NoType } case RefinedThis(rt) => @@ -1915,7 +1912,7 @@ object Types { case MethodParam(`thisMethodType`, _) => true case tp @ TypeRef(MethodParam(`thisMethodType`, _), name) => tp.info match { // follow type arguments to avoid dependency - case TypeBounds(lo, hi) if lo eq hi => apply(x, hi) + case TypeAlias(tp)=> apply(x, tp) case _ => true } case _ => -- cgit v1.2.3