Permalink
Browse files

SI-5841 reification of renamed imports

Reification of renamed imports is done by catching Selects with name != their tree.symbol.name,
replacing this name with tree.symbol.name, and then doing reifyProduct in case
of renamed terms and reifyBoundType (inner) in case of renamed types.
  • Loading branch information...
1 parent 0acb8a3 commit 286abfc4cf6ed41c1622f4964aae321b0b9b6c6d @apsk apsk committed with xeno-by Dec 6, 2012
@@ -147,6 +147,11 @@ trait GenTrees {
}
case tree @ Ident(_) if tree.symbol.isLocalToReifee =>
mirrorCall(nme.Ident, reify(tree.name))
+ case Select(qual, name) =>
+ if (tree.symbol != NoSymbol && tree.symbol.name != name)
+ reifyProduct(Select(qual, tree.symbol.name))
+ else
+ reifyProduct(tree)
case _ =>
throw new Error("internal error: %s (%s, %s) is not supported".format(tree, tree.productPrefix, tree.getClass))
}
@@ -196,6 +201,8 @@ trait GenTrees {
}
tree match {
+ case Select(qual, name) if (name != tree.symbol.name) =>
+ reifyBoundType(Select(qual, tree.symbol.name))
case Select(_, _) =>
reifyBoundType(tree)
case SelectFromTypeTree(_, _) =>
@@ -251,6 +251,8 @@ trait Extractors {
object BoundTerm {
def unapply(tree: Tree): Option[Tree] = tree match {
+ case Select(_, name) if name.isTermName =>
+ Some(tree)
case Ident(name) if name.isTermName =>
Some(tree)
case This(_) =>
@@ -0,0 +1 @@
+((),(),())
@@ -0,0 +1,20 @@
+import scala.reflect.runtime.universe._
+import scala.tools.reflect.Eval
+
+object A {
+ object B {
+ val c = ()
+ }
+}
+
+object Test extends App {
+ import A.{B => X}
+ import A.B.{c => y}
+ import X.{c => z}
+
+ val expr = reify (
+ X.c, y, z
+ )
+
+ println(expr.eval)
+}
@@ -0,0 +1 @@
+((),(),())
@@ -0,0 +1,20 @@
+import scala.reflect.runtime.universe._
+import scala.tools.reflect.Eval
+
+object A {
+ object B {
+ val c = ()
+ }
+}
+
+object Test extends App {
+ val expr = reify {
+ import A.{B => X}
+ import A.B.{c => y}
+ import X.{c => z}
+
+ (X.c, y, z)
+ }
+
+ println(expr.eval)
+}
@@ -0,0 +1,17 @@
+import scala.reflect.runtime.universe._
+import scala.tools.reflect.Eval
+
+object O {
+ def show(i: Int) = i.toString
+ def show(s: String) = s
+}
+
+object Test extends App {
+ import O.{show => s}
+
+ val expr = reify {
+ s("1") + s(2)
+ }
+
+ println(expr.eval)
+}
@@ -0,0 +1 @@
+class scala.reflect.runtime.JavaUniverse
@@ -0,0 +1,7 @@
+import scala.reflect.runtime.universe._
+import scala.reflect.runtime.{universe => ru}
+import scala.tools.reflect.Eval
+
+object Test extends App {
+ println(reify{ru}.eval.getClass)
+}
@@ -0,0 +1 @@
+()
@@ -0,0 +1,16 @@
+import scala.reflect.runtime.universe._
+import scala.tools.reflect.Eval
+
+object O {
+ type A = Unit
+}
+
+object Test extends App {
+ import O.{A => X}
+
+ def expr = reify {
+ val a: X = ()
+ }
+
+ println(expr.eval)
+}
@@ -0,0 +1,24 @@
+import scala.reflect.runtime.universe._
+import scala.tools.reflect.Eval
+
+object O {
+ type A = Unit
+}
+
+object Test extends App {
+ val expr = reify {
+ import O.{A => X}
+
+ val a: X = ()
+
+ object P {
+ type B = Unit
+ }
+
+ import P.{B => Y}
+
+ val b: Y = ()
+ }
+
+ println(expr.eval)
+}
@@ -0,0 +1 @@
+()
@@ -0,0 +1,21 @@
+import scala.reflect.runtime.universe._
+import scala.tools.reflect.Eval
+
+abstract class C {
+ type T >: Null
+}
+
+object Test extends App {
+ def foo(c: C) = {
+ import c.{T => U}
+ reify {
+ val x: U = null
+ }
+ }
+
+ val expr = foo(new C {
+ type T = AnyRef
+ })
+
+ println(expr.eval)
+}

0 comments on commit 286abfc

Please sign in to comment.