summaryrefslogtreecommitdiff
path: root/test/files/run/macro-duplicate
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2012-12-25 14:09:33 +0100
committerEugene Burmako <xeno.by@gmail.com>2012-12-25 14:09:33 +0100
commit48cdfefb95ee43ded08688d6c99a8c3a32d47f18 (patch)
tree8afef91284098f0e78e9995349b73db3dd716940 /test/files/run/macro-duplicate
parentd2a7aa4ba1c048e52affb0eb2b9167a18dc29c83 (diff)
downloadscala-48cdfefb95ee43ded08688d6c99a8c3a32d47f18.tar.gz
scala-48cdfefb95ee43ded08688d6c99a8c3a32d47f18.tar.bz2
scala-48cdfefb95ee43ded08688d6c99a8c3a32d47f18.zip
macro expansions are now auto-duplicated
The fix still requires macro developers to be careful about sharing trees by references, because attributed DefTrees will still bring trouble. However this is an improvement, because it doesn't make matters worse and automatically fixes situations similar to one in the test. A much more thorough discussion with a number of open questions left: http://groups.google.com/group/scala-internals/browse_thread/thread/492560d941b315cc
Diffstat (limited to 'test/files/run/macro-duplicate')
-rw-r--r--test/files/run/macro-duplicate/Impls_Macros_1.scala29
-rw-r--r--test/files/run/macro-duplicate/Test_2.scala6
2 files changed, 35 insertions, 0 deletions
diff --git a/test/files/run/macro-duplicate/Impls_Macros_1.scala b/test/files/run/macro-duplicate/Impls_Macros_1.scala
new file mode 100644
index 0000000000..de81923330
--- /dev/null
+++ b/test/files/run/macro-duplicate/Impls_Macros_1.scala
@@ -0,0 +1,29 @@
+import scala.reflect.macros.Context
+
+object Macros {
+ def impl(c: Context) = {
+ import c.universe._
+ val Expr(Block((cdef: ClassDef) :: Nil, _)) = reify { class C { def x = 2 } }
+ val cdef1 =
+ new Transformer {
+ override def transform(tree: Tree): Tree = tree match {
+ case Template(_, _, ctor :: defs) =>
+ val defs1 = defs collect {
+ case ddef @ DefDef(mods, name, tparams, vparamss, tpt, body) =>
+ val future = Select(Select(Select(Ident(newTermName("scala")), newTermName("concurrent")), newTermName("package")), newTermName("future"))
+ val Future = Select(Select(Ident(newTermName("scala")), newTermName("concurrent")), newTypeName("Future"))
+ val tpt1 = if (tpt.isEmpty) tpt else AppliedTypeTree(Future, List(tpt))
+ val body1 = Apply(future, List(body))
+ val name1 = newTermName("async" + name.toString.capitalize)
+ DefDef(mods, name1, tparams, vparamss, tpt1, body1)
+ }
+ Template(Nil, emptyValDef, ctor +: defs ::: defs1)
+ case _ =>
+ super.transform(tree)
+ }
+ } transform cdef
+ c.Expr[Unit](Block(cdef1 :: Nil, Literal(Constant(()))))
+ }
+
+ def foo = macro impl
+} \ No newline at end of file
diff --git a/test/files/run/macro-duplicate/Test_2.scala b/test/files/run/macro-duplicate/Test_2.scala
new file mode 100644
index 0000000000..6dbd4382d3
--- /dev/null
+++ b/test/files/run/macro-duplicate/Test_2.scala
@@ -0,0 +1,6 @@
+import scala.concurrent._
+import ExecutionContext.Implicits.global
+
+object Test extends App {
+ Macros.foo
+} \ No newline at end of file