From f2c5b50e75e49c1947378d2e9c29dda559ea5cb9 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Wed, 18 Mar 2015 23:55:04 +0100 Subject: TypeErasure: simplify and fix bugs This commit tries to disentangle the TypeErasure class and the TypeErasure object thereby fixing #386. - Remove the `eraseInfo` method in the TypeErasure object, use `transformInfo` instead which takes care of using the correct instance of TypeErasure depending on the symbol to erase. - Remove the unused method `eraseResult` in the TypeErasure class. - In `transformInfo`, use the correct instance of the TypeErasure class when calling `eraseInfo`. - In the `eraseInfo` method of the TypeErasure class, do not call the `erasure` method of the TypeErasure object, instead use the `apply` method of the current instance of TypeErasure. --- src/dotty/tools/dotc/core/TypeErasure.scala | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'src/dotty/tools/dotc/core/TypeErasure.scala') diff --git a/src/dotty/tools/dotc/core/TypeErasure.scala b/src/dotty/tools/dotc/core/TypeErasure.scala index 20cf816c2..3afc5b9f9 100644 --- a/src/dotty/tools/dotc/core/TypeErasure.scala +++ b/src/dotty/tools/dotc/core/TypeErasure.scala @@ -117,19 +117,6 @@ object TypeErasure { erasure(tp) } - /** The erasure of a symbol's info. This is different of `erasure` in the way `ExprType`s are - * treated. `eraseInfo` maps them them to nullary method types, whereas `erasure` maps them - * to `Function0`. - */ - def eraseInfo(tp: Type, sym: Symbol)(implicit ctx: Context): Type = - scalaErasureFn.eraseInfo(tp, sym)(erasureCtx) - - /** The erasure of a function result type. Differs from normal erasure in that - * Unit is kept instead of being mapped to BoxedUnit. - */ - def eraseResult(tp: Type)(implicit ctx: Context): Type = - scalaErasureFn.eraseResult(tp)(erasureCtx) - /** The symbol's erased info. This is the type's erasure, except for the following symbols: * * - For $asInstanceOf : [T]T @@ -148,7 +135,7 @@ object TypeErasure { if (defn.isPolymorphicAfterErasure(sym)) eraseParamBounds(sym.info.asInstanceOf[PolyType]) else if (sym.isAbstractType) TypeAlias(WildcardType) else if (sym.isConstructor) outer.addParam(sym.owner.asClass, erase(tp)(erasureCtx)) - else eraseInfo(tp, sym)(erasureCtx) match { + else erase.eraseInfo(tp, sym)(erasureCtx) match { case einfo: MethodType if sym.isGetter && einfo.resultType.isRef(defn.UnitClass) => defn.BoxedUnitClass.typeRef case einfo => @@ -346,6 +333,10 @@ class TypeErasure(isJava: Boolean, isSemi: Boolean, isConstructor: Boolean, wild else JavaArrayType(this(elemtp)) } + /** The erasure of a symbol's info. This is different from `apply` in the way `ExprType`s are + * treated. `eraseInfo` maps them them to nullary method types, whereas `apply` maps them + * to `Function0`. + */ def eraseInfo(tp: Type, sym: Symbol)(implicit ctx: Context) = tp match { case ExprType(rt) => if (sym is Param) apply(tp) @@ -354,7 +345,7 @@ class TypeErasure(isJava: Boolean, isSemi: Boolean, isConstructor: Boolean, wild // forwarders to mixin methods. // See doc comment for ElimByName for speculation how we could improve this. else MethodType(Nil, Nil, eraseResult(rt)) - case tp => erasure(tp) + case tp => this(tp) } private def eraseDerivedValueClassRef(tref: TypeRef)(implicit ctx: Context): Type = @@ -365,6 +356,7 @@ class TypeErasure(isJava: Boolean, isSemi: Boolean, isConstructor: Boolean, wild (if (cls.owner is Package) normalizeClass(cls) else cls).typeRef } + /** The erasure of a function result type. */ private def eraseResult(tp: Type)(implicit ctx: Context): Type = tp match { case tp: TypeRef => val sym = tp.typeSymbol -- cgit v1.2.3