diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2012-12-29 05:22:31 -0800 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2012-12-29 05:22:31 -0800 |
commit | 26c27d831db5d68c4b65c0f1eb6d7286798814b5 (patch) | |
tree | cb8fd8b0144f15a4d579b79390ea58170f364f6d /test/files | |
parent | 8c7e034d528017afea18e9f345be71f7485380ee (diff) | |
parent | 48cdfefb95ee43ded08688d6c99a8c3a32d47f18 (diff) | |
download | scala-26c27d831db5d68c4b65c0f1eb6d7286798814b5.tar.gz scala-26c27d831db5d68c4b65c0f1eb6d7286798814b5.tar.bz2 scala-26c27d831db5d68c4b65c0f1eb6d7286798814b5.zip |
Merge pull request #1818 from scalamacros/topic/auto-duplicate-expansions
macro expansions are now auto-duplicated
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/run/macro-duplicate.check | 0 | ||||
-rw-r--r-- | test/files/run/macro-duplicate.flags | 1 | ||||
-rw-r--r-- | test/files/run/macro-duplicate/Impls_Macros_1.scala | 29 | ||||
-rw-r--r-- | test/files/run/macro-duplicate/Test_2.scala | 6 |
4 files changed, 36 insertions, 0 deletions
diff --git a/test/files/run/macro-duplicate.check b/test/files/run/macro-duplicate.check new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/files/run/macro-duplicate.check diff --git a/test/files/run/macro-duplicate.flags b/test/files/run/macro-duplicate.flags new file mode 100644 index 0000000000..cd66464f2f --- /dev/null +++ b/test/files/run/macro-duplicate.flags @@ -0,0 +1 @@ +-language:experimental.macros
\ No newline at end of file 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 |