aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/transform/Erasure.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-03-30 10:49:42 +0200
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2014-03-31 14:52:08 +0200
commit9bd1e6a99e1cb09a3527e548699d1561e72e36d3 (patch)
treee9f3899d05cf3cb2012e3f3032f1a3fc4da52415 /src/dotty/tools/dotc/transform/Erasure.scala
parentfc4648d33a051ff5d220c2fea097fc99b5883ecc (diff)
downloaddotty-9bd1e6a99e1cb09a3527e548699d1561e72e36d3.tar.gz
dotty-9bd1e6a99e1cb09a3527e548699d1561e72e36d3.tar.bz2
dotty-9bd1e6a99e1cb09a3527e548699d1561e72e36d3.zip
More fixes and tests for easure.
1. Object_isInstanceOf/asInstanceOf are no longer parameterized methods (seems there's no point in writing x.$asInstanceOf[T]() instead of the shorter x.$asInstanceOf[T]). 2. Array constructor's type is unchanged (the previous rules erased it to def <init>(len: Int)Object which is clearly wrong). 3. indexing needs to be disabled. 4. typedTypeApply needs to keep type applications that apply to type tests and type casts as well as array ops. 5. References to self-ids are typed ThisType(cls) before erasure; are replaced by This(cls) references during erasure.
Diffstat (limited to 'src/dotty/tools/dotc/transform/Erasure.scala')
-rw-r--r--src/dotty/tools/dotc/transform/Erasure.scala25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/dotty/tools/dotc/transform/Erasure.scala b/src/dotty/tools/dotc/transform/Erasure.scala
index f9b602f54..b403d4e66 100644
--- a/src/dotty/tools/dotc/transform/Erasure.scala
+++ b/src/dotty/tools/dotc/transform/Erasure.scala
@@ -130,7 +130,7 @@ object Erasure {
// See SI-2386 for one example of when this might be necessary.
cast(runtimeCall(nme.toObjectArray, tree :: Nil), pt)
case _ =>
- println(s"casting from ${tree.showSummary}: ${tree.tpe.show} to ${pt.show}")
+ ctx.log(s"casting from ${tree.showSummary}: ${tree.tpe.show} to ${pt.show}")
TypeApply(Select(tree, defn.Object_asInstanceOf), TypeTree(pt) :: Nil)
}
@@ -173,8 +173,10 @@ object Erasure {
override def typedIdent(tree: untpd.Ident, pt: Type)(implicit ctx: Context): Tree = {
val tree1 = promote(tree)
- println(i"typed ident ${tree.name}: ${tree1.tpe} at phase ${ctx.phase}, history = ${tree1.symbol.history}")
- tree1
+ tree1.tpe match {
+ case ThisType(cls) => This(cls) withPos tree.pos
+ case _ => tree1
+ }
}
/** Type check select nodes, applying the following rewritings exhaustively
@@ -226,8 +228,16 @@ object Erasure {
recur(typed(tree.qualifier, AnySelectionProto))
}
- override def typedTypeApply(tree: untpd.TypeApply, pt: Type)(implicit ctx: Context) =
- typedExpr(tree.fun, pt)
+ override def typedTypeApply(tree: untpd.TypeApply, pt: Type)(implicit ctx: Context) = {
+ val TypeApply(fun, args) = tree
+ val fun1 = typedExpr(fun, pt)
+ fun1.tpe.widen match {
+ case funTpe: PolyType =>
+ val args1 = args.mapconserve(typedType(_))
+ untpd.cpy.TypeApply(tree, fun1, args1).withType(funTpe.instantiate(args1.tpes))
+ case _ => fun1
+ }
+ }
override def typedApply(tree: untpd.Apply, pt: Type)(implicit ctx: Context): Tree = {
val Apply(fun, args) = tree
@@ -268,9 +278,8 @@ object Erasure {
*/
override def typedNamed(tree: untpd.NameTree, pt: Type)(implicit ctx: Context): Tree = {
if (tree eq untpd.EmptyValDef) return tpd.EmptyValDef
- assert(tree.hasType, tree)
+ assert(tree.hasType, tree.show)
val sym = tree.symbol
- assert(sym.exists, tree)
def localContext = ctx.fresh.setTree(tree).setOwner(sym)
tree match {
case tree: untpd.Ident => typedIdent(tree, pt)
@@ -288,5 +297,7 @@ object Erasure {
assert(ctx.phase == ctx.erasurePhase.next, ctx.phase)
if (tree.isEmpty) tree else adaptToType(tree, pt)
}
+
+ override def index(trees: List[untpd.Tree])(implicit ctx: Context) = ctx
}
} \ No newline at end of file