aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/TypeErasure.scala
diff options
context:
space:
mode:
authorGuillaume Martres <smarter@ubuntu.com>2015-03-18 23:55:04 +0100
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2015-05-01 13:26:22 +0200
commitf2c5b50e75e49c1947378d2e9c29dda559ea5cb9 (patch)
tree731bc07c66b59561bbcdc22e61b5bbb290059fbc /src/dotty/tools/dotc/core/TypeErasure.scala
parent57c893e5ddb2c976ae2e6098b06a3ec854996504 (diff)
downloaddotty-f2c5b50e75e49c1947378d2e9c29dda559ea5cb9.tar.gz
dotty-f2c5b50e75e49c1947378d2e9c29dda559ea5cb9.tar.bz2
dotty-f2c5b50e75e49c1947378d2e9c29dda559ea5cb9.zip
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.
Diffstat (limited to 'src/dotty/tools/dotc/core/TypeErasure.scala')
-rw-r--r--src/dotty/tools/dotc/core/TypeErasure.scala22
1 files changed, 7 insertions, 15 deletions
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