summaryrefslogtreecommitdiff
path: root/test/files/run/macro-auto-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>2013-08-14 22:45:41 +0200
commit75b44a6f723762cc3ebc911483beb2aec4cfee78 (patch)
tree0c4281d54e125daa5562c4601cd13062dc801a23 /test/files/run/macro-auto-duplicate
parented5c1abbfca18a880c79048cc7e9578ae932101d (diff)
downloadscala-75b44a6f723762cc3ebc911483beb2aec4cfee78.tar.gz
scala-75b44a6f723762cc3ebc911483beb2aec4cfee78.tar.bz2
scala-75b44a6f723762cc3ebc911483beb2aec4cfee78.zip
[nomaster] 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 Was fixed ages ago in master in one of the paradise backports. Never got to 2.10.x, but it's very useful, so I'm backporting it now.
Diffstat (limited to 'test/files/run/macro-auto-duplicate')
-rw-r--r--test/files/run/macro-auto-duplicate/Macros_1.scala17
-rw-r--r--test/files/run/macro-auto-duplicate/Test_2.scala3
2 files changed, 20 insertions, 0 deletions
diff --git a/test/files/run/macro-auto-duplicate/Macros_1.scala b/test/files/run/macro-auto-duplicate/Macros_1.scala
new file mode 100644
index 0000000000..e3df05ba50
--- /dev/null
+++ b/test/files/run/macro-auto-duplicate/Macros_1.scala
@@ -0,0 +1,17 @@
+import scala.reflect.macros.Context
+import language.experimental.macros
+
+object Macros {
+ def impl(c: Context) = {
+ import c.universe._
+ val x = Ident(newTermName("x"))
+ def defAndUseX(rhs: Tree) = {
+ Block(List(ValDef(NoMods, newTermName("x"), TypeTree(), rhs)), x)
+ }
+ val xi4 = defAndUseX(Literal(Constant(4)))
+ val xs2 = defAndUseX(Literal(Constant("2")))
+ c.Expr[String](Apply(Select(xi4, newTermName("$plus")), List(xs2)))
+ }
+
+ def foo = macro impl
+} \ No newline at end of file
diff --git a/test/files/run/macro-auto-duplicate/Test_2.scala b/test/files/run/macro-auto-duplicate/Test_2.scala
new file mode 100644
index 0000000000..f697da6020
--- /dev/null
+++ b/test/files/run/macro-auto-duplicate/Test_2.scala
@@ -0,0 +1,3 @@
+object Test extends App {
+ println(Macros.foo)
+} \ No newline at end of file