aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-11-08 09:39:35 +0100
committerMartin Odersky <odersky@gmail.com>2014-11-09 19:09:51 +0100
commitf618e471b3f4f035221234cfeb980e52cc283701 (patch)
treef77edcfd63bed2b5ea1fdc4105248ef2f5737be5 /src/dotty/tools/dotc
parent0f7934d42892f36e28154779588a1d2a80d80616 (diff)
downloaddotty-f618e471b3f4f035221234cfeb980e52cc283701.tar.gz
dotty-f618e471b3f4f035221234cfeb980e52cc283701.tar.bz2
dotty-f618e471b3f4f035221234cfeb980e52cc283701.zip
Fixes to Unit handling in erasure
1. Erase unit results in getters to BoxedUnit. 2. Erase => Unit to ()Unit; was ()BoxedUnit 3. Make sure ValDefs have same type in tpt as in symbol, analogous to DefDefs.
Diffstat (limited to 'src/dotty/tools/dotc')
-rw-r--r--src/dotty/tools/dotc/TypeErasure.scala12
-rw-r--r--src/dotty/tools/dotc/transform/Erasure.scala16
2 files changed, 23 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/TypeErasure.scala b/src/dotty/tools/dotc/TypeErasure.scala
index 2a55d6732..448dd3f57 100644
--- a/src/dotty/tools/dotc/TypeErasure.scala
+++ b/src/dotty/tools/dotc/TypeErasure.scala
@@ -4,6 +4,7 @@ package core
import Symbols._, Types._, Contexts._, Flags._, Names._, StdNames._, Decorators._, Flags.JavaDefined
import dotc.transform.ExplicitOuter._
+import typer.Mode
import util.DotClass
/** Erased types are:
@@ -89,7 +90,7 @@ object TypeErasure {
/** The current context with a phase no later than erasure */
private def erasureCtx(implicit ctx: Context) =
- if (ctx.erasedTypes) ctx.withPhase(ctx.erasurePhase) else ctx
+ if (ctx.erasedTypes) ctx.withPhase(ctx.erasurePhase).addMode(Mode.FutureDefsOK) else ctx
def erasure(tp: Type)(implicit ctx: Context): Type = scalaErasureFn(tp)(erasureCtx)
def semiErasure(tp: Type)(implicit ctx: Context): Type = semiErasureFn(tp)(erasureCtx)
@@ -141,7 +142,12 @@ object TypeErasure {
if ((sym eq defn.Any_asInstanceOf) || (sym eq defn.Any_isInstanceOf)) 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)(erasureCtx)
+ else eraseInfo(tp)(erasureCtx) match {
+ case einfo: MethodType if sym.isGetter && einfo.resultType.isRef(defn.UnitClass) =>
+ defn.BoxedUnitClass.typeRef
+ case einfo =>
+ einfo
+ }
}
def isUnboundedGeneric(tp: Type)(implicit ctx: Context) = !(
@@ -319,7 +325,7 @@ class TypeErasure(isJava: Boolean, isSemi: Boolean, isConstructor: Boolean, wild
}
def eraseInfo(tp: Type)(implicit ctx: Context) = tp match {
- case ExprType(rt) => MethodType(Nil, Nil, erasure(rt))
+ case ExprType(rt) => MethodType(Nil, Nil, eraseResult(rt))
case tp => erasure(tp)
}
diff --git a/src/dotty/tools/dotc/transform/Erasure.scala b/src/dotty/tools/dotc/transform/Erasure.scala
index fd9048157..b51a2360e 100644
--- a/src/dotty/tools/dotc/transform/Erasure.scala
+++ b/src/dotty/tools/dotc/transform/Erasure.scala
@@ -247,6 +247,10 @@ object Erasure extends TypeTestsCasts{
tree.withType(erased)
}
+ override def typedLiteral(tree: untpd.Literal)(implicit ctc: Context): Literal =
+ if (tree.typeOpt.isRef(defn.UnitClass)) tree.withType(tree.typeOpt)
+ else super.typedLiteral(tree)
+
/** Type check select nodes, applying the following rewritings exhaustively
* on selections `e.m`, where `OT` is the type of the owner of `m` and `ET`
* is the erased type of the selection's original qualifier expression.
@@ -369,12 +373,20 @@ object Erasure extends TypeTestsCasts{
}
}
+ override def typedValDef(vdef: untpd.ValDef, sym: Symbol)(implicit ctx: Context): ValDef =
+ super.typedValDef(untpd.cpy.ValDef(vdef)(
+ tpt = untpd.TypedSplice(TypeTree(sym.info).withPos(vdef.tpt.pos))), sym)
+
override def typedDefDef(ddef: untpd.DefDef, sym: Symbol)(implicit ctx: Context) = {
+ val restpe = sym.info.resultType
val ddef1 = untpd.cpy.DefDef(ddef)(
tparams = Nil,
vparamss = ddef.vparamss.flatten :: Nil,
- tpt = // keep UnitTypes intact in result position
- untpd.TypedSplice(TypeTree(eraseResult(ddef.tpt.typeOpt)).withPos(ddef.tpt.pos)))
+ tpt = untpd.TypedSplice(TypeTree(restpe).withPos(ddef.tpt.pos)),
+ rhs = ddef.rhs match {
+ case id @ Ident(nme.WILDCARD) => untpd.TypedSplice(id.withType(restpe))
+ case _ => ddef.rhs
+ })
super.typedDefDef(ddef1, sym)
}