Skip to content

Commit a00ceed

Browse files
committed
TypeErasure: simplify and fix bugs
This commit tries to disentangle the TypeErasure class and the TypeErasure object thereby fixing scala#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.
1 parent 3c07ce1 commit a00ceed

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

src/dotty/tools/dotc/TypeErasure.scala

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,6 @@ object TypeErasure {
117117
erasure(tp)
118118
}
119119

120-
/** The erasure of a symbol's info. This is different of `erasure` in the way `ExprType`s are
121-
* treated. `eraseInfo` maps them them to nullary method types, whereas `erasure` maps them
122-
* to `Function0`.
123-
*/
124-
def eraseInfo(tp: Type, sym: Symbol)(implicit ctx: Context): Type =
125-
scalaErasureFn.eraseInfo(tp, sym)(erasureCtx)
126-
127-
/** The erasure of a function result type. Differs from normal erasure in that
128-
* Unit is kept instead of being mapped to BoxedUnit.
129-
*/
130-
def eraseResult(tp: Type)(implicit ctx: Context): Type =
131-
scalaErasureFn.eraseResult(tp)(erasureCtx)
132-
133120
/** The symbol's erased info. This is the type's erasure, except for the following symbols:
134121
*
135122
* - For $asInstanceOf : [T]T
@@ -148,7 +135,7 @@ object TypeErasure {
148135
if (defn.isPolymorphicAfterErasure(sym)) eraseParamBounds(sym.info.asInstanceOf[PolyType])
149136
else if (sym.isAbstractType) TypeAlias(WildcardType)
150137
else if (sym.isConstructor) outer.addParam(sym.owner.asClass, erase(tp)(erasureCtx))
151-
else eraseInfo(tp, sym)(erasureCtx) match {
138+
else erase.eraseInfo(tp, sym)(erasureCtx) match {
152139
case einfo: MethodType if sym.isGetter && einfo.resultType.isRef(defn.UnitClass) =>
153140
defn.BoxedUnitClass.typeRef
154141
case einfo =>
@@ -346,6 +333,10 @@ class TypeErasure(isJava: Boolean, isSemi: Boolean, isConstructor: Boolean, wild
346333
else JavaArrayType(this(elemtp))
347334
}
348335

336+
/** The erasure of a symbol's info. This is different from `apply` in the way `ExprType`s are
337+
* treated. `eraseInfo` maps them them to nullary method types, whereas `apply` maps them
338+
* to `Function0`.
339+
*/
349340
def eraseInfo(tp: Type, sym: Symbol)(implicit ctx: Context) = tp match {
350341
case ExprType(rt) =>
351342
if (sym is Param) apply(tp)
@@ -354,7 +345,7 @@ class TypeErasure(isJava: Boolean, isSemi: Boolean, isConstructor: Boolean, wild
354345
// forwarders to mixin methods.
355346
// See doc comment for ElimByName for speculation how we could improve this.
356347
else MethodType(Nil, Nil, eraseResult(rt))
357-
case tp => erasure(tp)
348+
case tp => this(tp)
358349
}
359350

360351
private def eraseDerivedValueClassRef(tref: TypeRef)(implicit ctx: Context): Type =
@@ -365,6 +356,7 @@ class TypeErasure(isJava: Boolean, isSemi: Boolean, isConstructor: Boolean, wild
365356
(if (cls.owner is Package) normalizeClass(cls) else cls).typeRef
366357
}
367358

359+
/** The erasure of a function result type. */
368360
private def eraseResult(tp: Type)(implicit ctx: Context): Type = tp match {
369361
case tp: TypeRef =>
370362
val sym = tp.typeSymbol

src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class Erasure extends Phase with DenotTransformer { thisTransformer =>
6262
}
6363
}
6464
case ref =>
65-
ref.derivedSingleDenotation(ref.symbol, eraseInfo(ref.info, ref.symbol))
65+
ref.derivedSingleDenotation(ref.symbol, transformInfo(ref.symbol, ref.info))
6666
}
6767

6868
val eraser = new Erasure.Typer

0 commit comments

Comments
 (0)