From 09fe97aec626b875f68e057828c44a9b6f4344dc Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 19 Feb 2014 20:37:46 +0100 Subject: SI-8316 SI-8318 SI-8248 reintroduces resetAllAttrs Unfortunately, due to the aforementioned bugs we have to delay our triumph over resetAllAttrs. Therefore, I'm rolling back the internal changes to scalac introduced in https://github.com/scala/scala/pull/3485. Our public reflection API interface in Scala 2.11 is still going to contain only resetLocalAttrs, but both the reifier and the label typechecker are too heavily addicted to resetAllAttrs to do away with it right now. --- .../run/macro-reify-chained1/Impls_Macros_1.scala | 47 ++++++++++++++++++++++ test/files/run/macro-reify-chained1/Test_2.scala | 9 +++++ .../run/macro-reify-chained2/Impls_Macros_1.scala | 47 ++++++++++++++++++++++ test/files/run/macro-reify-chained2/Test_2.scala | 9 +++++ test/files/run/macro-reify-nested-a.flags | 1 - .../run/macro-reify-nested-a/Impls_Macros_1.scala | 46 --------------------- test/files/run/macro-reify-nested-a/Test_2.scala | 4 -- .../run/macro-reify-nested-a1/Impls_Macros_1.scala | 47 ++++++++++++++++++++++ test/files/run/macro-reify-nested-a1/Test_2.scala | 9 +++++ .../run/macro-reify-nested-a2/Impls_Macros_1.scala | 47 ++++++++++++++++++++++ test/files/run/macro-reify-nested-a2/Test_2.scala | 9 +++++ test/files/run/macro-reify-nested-b.flags | 1 - .../run/macro-reify-nested-b/Impls_Macros_1.scala | 46 --------------------- test/files/run/macro-reify-nested-b/Test_2.scala | 4 -- .../run/macro-reify-nested-b1/Impls_Macros_1.scala | 47 ++++++++++++++++++++++ test/files/run/macro-reify-nested-b1/Test_2.scala | 9 +++++ .../run/macro-reify-nested-b2/Impls_Macros_1.scala | 47 ++++++++++++++++++++++ test/files/run/macro-reify-nested-b2/Test_2.scala | 9 +++++ 18 files changed, 336 insertions(+), 102 deletions(-) create mode 100644 test/files/run/macro-reify-chained1/Impls_Macros_1.scala create mode 100644 test/files/run/macro-reify-chained1/Test_2.scala create mode 100644 test/files/run/macro-reify-chained2/Impls_Macros_1.scala create mode 100644 test/files/run/macro-reify-chained2/Test_2.scala delete mode 100644 test/files/run/macro-reify-nested-a.flags delete mode 100644 test/files/run/macro-reify-nested-a/Impls_Macros_1.scala delete mode 100644 test/files/run/macro-reify-nested-a/Test_2.scala create mode 100644 test/files/run/macro-reify-nested-a1/Impls_Macros_1.scala create mode 100644 test/files/run/macro-reify-nested-a1/Test_2.scala create mode 100644 test/files/run/macro-reify-nested-a2/Impls_Macros_1.scala create mode 100644 test/files/run/macro-reify-nested-a2/Test_2.scala delete mode 100644 test/files/run/macro-reify-nested-b.flags delete mode 100644 test/files/run/macro-reify-nested-b/Impls_Macros_1.scala delete mode 100644 test/files/run/macro-reify-nested-b/Test_2.scala create mode 100644 test/files/run/macro-reify-nested-b1/Impls_Macros_1.scala create mode 100644 test/files/run/macro-reify-nested-b1/Test_2.scala create mode 100644 test/files/run/macro-reify-nested-b2/Impls_Macros_1.scala create mode 100644 test/files/run/macro-reify-nested-b2/Test_2.scala (limited to 'test/files/run') diff --git a/test/files/run/macro-reify-chained1/Impls_Macros_1.scala b/test/files/run/macro-reify-chained1/Impls_Macros_1.scala new file mode 100644 index 0000000000..7f877b2729 --- /dev/null +++ b/test/files/run/macro-reify-chained1/Impls_Macros_1.scala @@ -0,0 +1,47 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{universe => ru} +import scala.reflect.macros.blackbox.Context +import scala.language.experimental.macros + +case class Utils[C <: Context]( c:C ) { + import c.universe._ + import c.{Tree=>_} + object removeDoubleReify extends c.universe.Transformer { + def apply( tree:Tree ) = transform(tree) + override def transform(tree: Tree): Tree = { + super.transform { + tree match { + case Apply(TypeApply(Select(_this, termname), _), reification::Nil ) + if termname.toString == "factory" => c.unreifyTree(reification) + case Apply(Select(_this, termname), reification::Nil ) + if termname.toString == "factory" => c.unreifyTree(reification) + case _ => tree + } + } + } + } +} +object QueryableMacros{ + def _helper[C <: Context,S:c.WeakTypeTag]( c:C )( name:String, projection:c.Expr[_] ) = { + import c.universe._ + import internal._ + val element_type = implicitly[c.WeakTypeTag[S]].tpe + val foo = c.Expr[ru.Expr[Queryable[S]]]( + c.reifyTree( gen.mkRuntimeUniverseRef, EmptyTree, c.typecheck( + Utils[c.type](c).removeDoubleReify( + Apply(Select(c.prefix.tree, TermName( name )), List( projection.tree )) + ).asInstanceOf[Tree] + ))) + c.universe.reify{ Queryable.factory[S]( foo.splice )} + } + def map[T:c.WeakTypeTag, S:c.WeakTypeTag] + (c: Context) + (projection: c.Expr[T => S]): c.Expr[Queryable[S]] = _helper[c.type,S]( c )( "_map", projection ) +} +class Queryable[T]{ + def _map[S]( projection: T => S ) : Queryable[S] = ??? + def map[S]( projection: T => S ) : Queryable[S] = macro QueryableMacros.map[T,S] +} +object Queryable{ + def factory[S]( projection:ru.Expr[Queryable[S]] ) : Queryable[S] = null +} \ No newline at end of file diff --git a/test/files/run/macro-reify-chained1/Test_2.scala b/test/files/run/macro-reify-chained1/Test_2.scala new file mode 100644 index 0000000000..2adb07b035 --- /dev/null +++ b/test/files/run/macro-reify-chained1/Test_2.scala @@ -0,0 +1,9 @@ +object Test extends App{ + val q : Queryable[Any] = new Queryable[Any] + q.map(x => x).map(x => x) + + locally { + val q : Queryable[Any] = new Queryable[Any] + q.map(x => x).map(x => x) + } +} \ No newline at end of file diff --git a/test/files/run/macro-reify-chained2/Impls_Macros_1.scala b/test/files/run/macro-reify-chained2/Impls_Macros_1.scala new file mode 100644 index 0000000000..965b191044 --- /dev/null +++ b/test/files/run/macro-reify-chained2/Impls_Macros_1.scala @@ -0,0 +1,47 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{universe => ru} +import scala.reflect.macros.whitebox.Context +import scala.language.experimental.macros + +case class Utils[C <: Context]( c:C ) { + import c.universe._ + import c.{Tree=>_} + object removeDoubleReify extends c.universe.Transformer { + def apply( tree:Tree ) = transform(tree) + override def transform(tree: Tree): Tree = { + super.transform { + tree match { + case Apply(TypeApply(Select(_this, termname), _), reification::Nil ) + if termname.toString == "factory" => c.unreifyTree(reification) + case Apply(Select(_this, termname), reification::Nil ) + if termname.toString == "factory" => c.unreifyTree(reification) + case _ => tree + } + } + } + } +} +object QueryableMacros{ + def _helper[C <: Context,S:c.WeakTypeTag]( c:C )( name:String, projection:c.Expr[_] ) = { + import c.universe._ + import internal._ + val element_type = implicitly[c.WeakTypeTag[S]].tpe + val foo = c.Expr[ru.Expr[Queryable[S]]]( + c.reifyTree( gen.mkRuntimeUniverseRef, EmptyTree, c.typecheck( + Utils[c.type](c).removeDoubleReify( + Apply(Select(c.prefix.tree, TermName( name )), List( projection.tree )) + ).asInstanceOf[Tree] + ))) + c.universe.reify{ Queryable.factory[S]( foo.splice )} + } + def map[T:c.WeakTypeTag, S:c.WeakTypeTag] + (c: Context) + (projection: c.Expr[T => S]): c.Expr[Queryable[S]] = _helper[c.type,S]( c )( "_map", projection ) +} +class Queryable[T]{ + def _map[S]( projection: T => S ) : Queryable[S] = ??? + def map[S]( projection: T => S ) : Queryable[S] = macro QueryableMacros.map[T,S] +} +object Queryable{ + def factory[S]( projection:ru.Expr[Queryable[S]] ) : Queryable[S] = null +} \ No newline at end of file diff --git a/test/files/run/macro-reify-chained2/Test_2.scala b/test/files/run/macro-reify-chained2/Test_2.scala new file mode 100644 index 0000000000..2adb07b035 --- /dev/null +++ b/test/files/run/macro-reify-chained2/Test_2.scala @@ -0,0 +1,9 @@ +object Test extends App{ + val q : Queryable[Any] = new Queryable[Any] + q.map(x => x).map(x => x) + + locally { + val q : Queryable[Any] = new Queryable[Any] + q.map(x => x).map(x => x) + } +} \ No newline at end of file diff --git a/test/files/run/macro-reify-nested-a.flags b/test/files/run/macro-reify-nested-a.flags deleted file mode 100644 index cd66464f2f..0000000000 --- a/test/files/run/macro-reify-nested-a.flags +++ /dev/null @@ -1 +0,0 @@ --language:experimental.macros \ No newline at end of file diff --git a/test/files/run/macro-reify-nested-a/Impls_Macros_1.scala b/test/files/run/macro-reify-nested-a/Impls_Macros_1.scala deleted file mode 100644 index 3bea04cead..0000000000 --- a/test/files/run/macro-reify-nested-a/Impls_Macros_1.scala +++ /dev/null @@ -1,46 +0,0 @@ -import scala.reflect.runtime.universe._ -import scala.reflect.runtime.{universe => ru} -import scala.reflect.macros.blackbox.Context - -case class Utils[C <: Context]( c:C ) { - import c.universe._ - import c.{Tree=>_} - object removeDoubleReify extends c.universe.Transformer { - def apply( tree:Tree ) = transform(tree) - override def transform(tree: Tree): Tree = { - super.transform { - tree match { - case Apply(TypeApply(Select(_this, termname), _), reification::Nil ) - if termname.toString == "factory" => c.unreifyTree(reification) - case Apply(Select(_this, termname), reification::Nil ) - if termname.toString == "factory" => c.unreifyTree(reification) - case _ => tree - } - } - } - } -} -object QueryableMacros{ - def _helper[C <: Context,S:c.WeakTypeTag]( c:C )( name:String, projection:c.Expr[_] ) = { - import c.universe._ - import internal._ - val element_type = implicitly[c.WeakTypeTag[S]].tpe - val foo = c.Expr[ru.Expr[Queryable[S]]]( - c.reifyTree( gen.mkRuntimeUniverseRef, EmptyTree, c.typecheck( - Utils[c.type](c).removeDoubleReify( - Apply(Select(c.prefix.tree, TermName( name )), List( projection.tree )) - ).asInstanceOf[Tree] - ))) - c.universe.reify{ Queryable.factory[S]( foo.splice )} - } - def map[T:c.WeakTypeTag, S:c.WeakTypeTag] - (c: scala.reflect.macros.blackbox.Context) - (projection: c.Expr[T => S]): c.Expr[Queryable[S]] = _helper[c.type,S]( c )( "_map", projection ) -} -class Queryable[T]{ - def _map[S]( projection: T => S ) : Queryable[S] = ??? - def map[S]( projection: T => S ) : Queryable[S] = macro QueryableMacros.map[T,S] -} -object Queryable{ - def factory[S]( projection:ru.Expr[Queryable[S]] ) : Queryable[S] = null -} \ No newline at end of file diff --git a/test/files/run/macro-reify-nested-a/Test_2.scala b/test/files/run/macro-reify-nested-a/Test_2.scala deleted file mode 100644 index fa0eb378af..0000000000 --- a/test/files/run/macro-reify-nested-a/Test_2.scala +++ /dev/null @@ -1,4 +0,0 @@ -object Test extends App{ - val q : Queryable[Any] = new Queryable[Any] - q.map(e1 => q.map(e2=>e1)) -} \ No newline at end of file diff --git a/test/files/run/macro-reify-nested-a1/Impls_Macros_1.scala b/test/files/run/macro-reify-nested-a1/Impls_Macros_1.scala new file mode 100644 index 0000000000..7f877b2729 --- /dev/null +++ b/test/files/run/macro-reify-nested-a1/Impls_Macros_1.scala @@ -0,0 +1,47 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{universe => ru} +import scala.reflect.macros.blackbox.Context +import scala.language.experimental.macros + +case class Utils[C <: Context]( c:C ) { + import c.universe._ + import c.{Tree=>_} + object removeDoubleReify extends c.universe.Transformer { + def apply( tree:Tree ) = transform(tree) + override def transform(tree: Tree): Tree = { + super.transform { + tree match { + case Apply(TypeApply(Select(_this, termname), _), reification::Nil ) + if termname.toString == "factory" => c.unreifyTree(reification) + case Apply(Select(_this, termname), reification::Nil ) + if termname.toString == "factory" => c.unreifyTree(reification) + case _ => tree + } + } + } + } +} +object QueryableMacros{ + def _helper[C <: Context,S:c.WeakTypeTag]( c:C )( name:String, projection:c.Expr[_] ) = { + import c.universe._ + import internal._ + val element_type = implicitly[c.WeakTypeTag[S]].tpe + val foo = c.Expr[ru.Expr[Queryable[S]]]( + c.reifyTree( gen.mkRuntimeUniverseRef, EmptyTree, c.typecheck( + Utils[c.type](c).removeDoubleReify( + Apply(Select(c.prefix.tree, TermName( name )), List( projection.tree )) + ).asInstanceOf[Tree] + ))) + c.universe.reify{ Queryable.factory[S]( foo.splice )} + } + def map[T:c.WeakTypeTag, S:c.WeakTypeTag] + (c: Context) + (projection: c.Expr[T => S]): c.Expr[Queryable[S]] = _helper[c.type,S]( c )( "_map", projection ) +} +class Queryable[T]{ + def _map[S]( projection: T => S ) : Queryable[S] = ??? + def map[S]( projection: T => S ) : Queryable[S] = macro QueryableMacros.map[T,S] +} +object Queryable{ + def factory[S]( projection:ru.Expr[Queryable[S]] ) : Queryable[S] = null +} \ No newline at end of file diff --git a/test/files/run/macro-reify-nested-a1/Test_2.scala b/test/files/run/macro-reify-nested-a1/Test_2.scala new file mode 100644 index 0000000000..b99c4c55e4 --- /dev/null +++ b/test/files/run/macro-reify-nested-a1/Test_2.scala @@ -0,0 +1,9 @@ +object Test extends App{ + val q : Queryable[Any] = new Queryable[Any] + q.map(e1 => q.map(e2=>e1)) + + locally { + val q : Queryable[Any] = new Queryable[Any] + q.map(e1 => q.map(e2=>e1)) + } +} \ No newline at end of file diff --git a/test/files/run/macro-reify-nested-a2/Impls_Macros_1.scala b/test/files/run/macro-reify-nested-a2/Impls_Macros_1.scala new file mode 100644 index 0000000000..965b191044 --- /dev/null +++ b/test/files/run/macro-reify-nested-a2/Impls_Macros_1.scala @@ -0,0 +1,47 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{universe => ru} +import scala.reflect.macros.whitebox.Context +import scala.language.experimental.macros + +case class Utils[C <: Context]( c:C ) { + import c.universe._ + import c.{Tree=>_} + object removeDoubleReify extends c.universe.Transformer { + def apply( tree:Tree ) = transform(tree) + override def transform(tree: Tree): Tree = { + super.transform { + tree match { + case Apply(TypeApply(Select(_this, termname), _), reification::Nil ) + if termname.toString == "factory" => c.unreifyTree(reification) + case Apply(Select(_this, termname), reification::Nil ) + if termname.toString == "factory" => c.unreifyTree(reification) + case _ => tree + } + } + } + } +} +object QueryableMacros{ + def _helper[C <: Context,S:c.WeakTypeTag]( c:C )( name:String, projection:c.Expr[_] ) = { + import c.universe._ + import internal._ + val element_type = implicitly[c.WeakTypeTag[S]].tpe + val foo = c.Expr[ru.Expr[Queryable[S]]]( + c.reifyTree( gen.mkRuntimeUniverseRef, EmptyTree, c.typecheck( + Utils[c.type](c).removeDoubleReify( + Apply(Select(c.prefix.tree, TermName( name )), List( projection.tree )) + ).asInstanceOf[Tree] + ))) + c.universe.reify{ Queryable.factory[S]( foo.splice )} + } + def map[T:c.WeakTypeTag, S:c.WeakTypeTag] + (c: Context) + (projection: c.Expr[T => S]): c.Expr[Queryable[S]] = _helper[c.type,S]( c )( "_map", projection ) +} +class Queryable[T]{ + def _map[S]( projection: T => S ) : Queryable[S] = ??? + def map[S]( projection: T => S ) : Queryable[S] = macro QueryableMacros.map[T,S] +} +object Queryable{ + def factory[S]( projection:ru.Expr[Queryable[S]] ) : Queryable[S] = null +} \ No newline at end of file diff --git a/test/files/run/macro-reify-nested-a2/Test_2.scala b/test/files/run/macro-reify-nested-a2/Test_2.scala new file mode 100644 index 0000000000..b99c4c55e4 --- /dev/null +++ b/test/files/run/macro-reify-nested-a2/Test_2.scala @@ -0,0 +1,9 @@ +object Test extends App{ + val q : Queryable[Any] = new Queryable[Any] + q.map(e1 => q.map(e2=>e1)) + + locally { + val q : Queryable[Any] = new Queryable[Any] + q.map(e1 => q.map(e2=>e1)) + } +} \ No newline at end of file diff --git a/test/files/run/macro-reify-nested-b.flags b/test/files/run/macro-reify-nested-b.flags deleted file mode 100644 index cd66464f2f..0000000000 --- a/test/files/run/macro-reify-nested-b.flags +++ /dev/null @@ -1 +0,0 @@ --language:experimental.macros \ No newline at end of file diff --git a/test/files/run/macro-reify-nested-b/Impls_Macros_1.scala b/test/files/run/macro-reify-nested-b/Impls_Macros_1.scala deleted file mode 100644 index 3bea04cead..0000000000 --- a/test/files/run/macro-reify-nested-b/Impls_Macros_1.scala +++ /dev/null @@ -1,46 +0,0 @@ -import scala.reflect.runtime.universe._ -import scala.reflect.runtime.{universe => ru} -import scala.reflect.macros.blackbox.Context - -case class Utils[C <: Context]( c:C ) { - import c.universe._ - import c.{Tree=>_} - object removeDoubleReify extends c.universe.Transformer { - def apply( tree:Tree ) = transform(tree) - override def transform(tree: Tree): Tree = { - super.transform { - tree match { - case Apply(TypeApply(Select(_this, termname), _), reification::Nil ) - if termname.toString == "factory" => c.unreifyTree(reification) - case Apply(Select(_this, termname), reification::Nil ) - if termname.toString == "factory" => c.unreifyTree(reification) - case _ => tree - } - } - } - } -} -object QueryableMacros{ - def _helper[C <: Context,S:c.WeakTypeTag]( c:C )( name:String, projection:c.Expr[_] ) = { - import c.universe._ - import internal._ - val element_type = implicitly[c.WeakTypeTag[S]].tpe - val foo = c.Expr[ru.Expr[Queryable[S]]]( - c.reifyTree( gen.mkRuntimeUniverseRef, EmptyTree, c.typecheck( - Utils[c.type](c).removeDoubleReify( - Apply(Select(c.prefix.tree, TermName( name )), List( projection.tree )) - ).asInstanceOf[Tree] - ))) - c.universe.reify{ Queryable.factory[S]( foo.splice )} - } - def map[T:c.WeakTypeTag, S:c.WeakTypeTag] - (c: scala.reflect.macros.blackbox.Context) - (projection: c.Expr[T => S]): c.Expr[Queryable[S]] = _helper[c.type,S]( c )( "_map", projection ) -} -class Queryable[T]{ - def _map[S]( projection: T => S ) : Queryable[S] = ??? - def map[S]( projection: T => S ) : Queryable[S] = macro QueryableMacros.map[T,S] -} -object Queryable{ - def factory[S]( projection:ru.Expr[Queryable[S]] ) : Queryable[S] = null -} \ No newline at end of file diff --git a/test/files/run/macro-reify-nested-b/Test_2.scala b/test/files/run/macro-reify-nested-b/Test_2.scala deleted file mode 100644 index fa13f57ffb..0000000000 --- a/test/files/run/macro-reify-nested-b/Test_2.scala +++ /dev/null @@ -1,4 +0,0 @@ -object Test extends App{ - val q : Queryable[Any] = new Queryable[Any] - q.map(e1 => q.map(e2=>e1).map(e2=>e1)) -} \ No newline at end of file diff --git a/test/files/run/macro-reify-nested-b1/Impls_Macros_1.scala b/test/files/run/macro-reify-nested-b1/Impls_Macros_1.scala new file mode 100644 index 0000000000..7f877b2729 --- /dev/null +++ b/test/files/run/macro-reify-nested-b1/Impls_Macros_1.scala @@ -0,0 +1,47 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{universe => ru} +import scala.reflect.macros.blackbox.Context +import scala.language.experimental.macros + +case class Utils[C <: Context]( c:C ) { + import c.universe._ + import c.{Tree=>_} + object removeDoubleReify extends c.universe.Transformer { + def apply( tree:Tree ) = transform(tree) + override def transform(tree: Tree): Tree = { + super.transform { + tree match { + case Apply(TypeApply(Select(_this, termname), _), reification::Nil ) + if termname.toString == "factory" => c.unreifyTree(reification) + case Apply(Select(_this, termname), reification::Nil ) + if termname.toString == "factory" => c.unreifyTree(reification) + case _ => tree + } + } + } + } +} +object QueryableMacros{ + def _helper[C <: Context,S:c.WeakTypeTag]( c:C )( name:String, projection:c.Expr[_] ) = { + import c.universe._ + import internal._ + val element_type = implicitly[c.WeakTypeTag[S]].tpe + val foo = c.Expr[ru.Expr[Queryable[S]]]( + c.reifyTree( gen.mkRuntimeUniverseRef, EmptyTree, c.typecheck( + Utils[c.type](c).removeDoubleReify( + Apply(Select(c.prefix.tree, TermName( name )), List( projection.tree )) + ).asInstanceOf[Tree] + ))) + c.universe.reify{ Queryable.factory[S]( foo.splice )} + } + def map[T:c.WeakTypeTag, S:c.WeakTypeTag] + (c: Context) + (projection: c.Expr[T => S]): c.Expr[Queryable[S]] = _helper[c.type,S]( c )( "_map", projection ) +} +class Queryable[T]{ + def _map[S]( projection: T => S ) : Queryable[S] = ??? + def map[S]( projection: T => S ) : Queryable[S] = macro QueryableMacros.map[T,S] +} +object Queryable{ + def factory[S]( projection:ru.Expr[Queryable[S]] ) : Queryable[S] = null +} \ No newline at end of file diff --git a/test/files/run/macro-reify-nested-b1/Test_2.scala b/test/files/run/macro-reify-nested-b1/Test_2.scala new file mode 100644 index 0000000000..b199036349 --- /dev/null +++ b/test/files/run/macro-reify-nested-b1/Test_2.scala @@ -0,0 +1,9 @@ +object Test extends App{ + val q : Queryable[Any] = new Queryable[Any] + q.map(e1 => q.map(e2=>e1).map(e2=>e1)) + + locally { + val q : Queryable[Any] = new Queryable[Any] + q.map(e1 => q.map(e2=>e1).map(e2=>e1)) + } +} \ No newline at end of file diff --git a/test/files/run/macro-reify-nested-b2/Impls_Macros_1.scala b/test/files/run/macro-reify-nested-b2/Impls_Macros_1.scala new file mode 100644 index 0000000000..965b191044 --- /dev/null +++ b/test/files/run/macro-reify-nested-b2/Impls_Macros_1.scala @@ -0,0 +1,47 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{universe => ru} +import scala.reflect.macros.whitebox.Context +import scala.language.experimental.macros + +case class Utils[C <: Context]( c:C ) { + import c.universe._ + import c.{Tree=>_} + object removeDoubleReify extends c.universe.Transformer { + def apply( tree:Tree ) = transform(tree) + override def transform(tree: Tree): Tree = { + super.transform { + tree match { + case Apply(TypeApply(Select(_this, termname), _), reification::Nil ) + if termname.toString == "factory" => c.unreifyTree(reification) + case Apply(Select(_this, termname), reification::Nil ) + if termname.toString == "factory" => c.unreifyTree(reification) + case _ => tree + } + } + } + } +} +object QueryableMacros{ + def _helper[C <: Context,S:c.WeakTypeTag]( c:C )( name:String, projection:c.Expr[_] ) = { + import c.universe._ + import internal._ + val element_type = implicitly[c.WeakTypeTag[S]].tpe + val foo = c.Expr[ru.Expr[Queryable[S]]]( + c.reifyTree( gen.mkRuntimeUniverseRef, EmptyTree, c.typecheck( + Utils[c.type](c).removeDoubleReify( + Apply(Select(c.prefix.tree, TermName( name )), List( projection.tree )) + ).asInstanceOf[Tree] + ))) + c.universe.reify{ Queryable.factory[S]( foo.splice )} + } + def map[T:c.WeakTypeTag, S:c.WeakTypeTag] + (c: Context) + (projection: c.Expr[T => S]): c.Expr[Queryable[S]] = _helper[c.type,S]( c )( "_map", projection ) +} +class Queryable[T]{ + def _map[S]( projection: T => S ) : Queryable[S] = ??? + def map[S]( projection: T => S ) : Queryable[S] = macro QueryableMacros.map[T,S] +} +object Queryable{ + def factory[S]( projection:ru.Expr[Queryable[S]] ) : Queryable[S] = null +} \ No newline at end of file diff --git a/test/files/run/macro-reify-nested-b2/Test_2.scala b/test/files/run/macro-reify-nested-b2/Test_2.scala new file mode 100644 index 0000000000..b199036349 --- /dev/null +++ b/test/files/run/macro-reify-nested-b2/Test_2.scala @@ -0,0 +1,9 @@ +object Test extends App{ + val q : Queryable[Any] = new Queryable[Any] + q.map(e1 => q.map(e2=>e1).map(e2=>e1)) + + locally { + val q : Queryable[Any] = new Queryable[Any] + q.map(e1 => q.map(e2=>e1).map(e2=>e1)) + } +} \ No newline at end of file -- cgit v1.2.3