diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2013-12-27 18:43:56 +0300 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2013-12-27 18:45:10 +0300 |
commit | bbd03b26f1eeba5abf495f5e745c6623f0cc05b7 (patch) | |
tree | d988476af3851a7e682f853c4058fe77e4fb4564 /test/files/run | |
parent | 9f0594c57716ed551918e15be6da843982e8ba12 (diff) | |
download | scala-bbd03b26f1eeba5abf495f5e745c6623f0cc05b7.tar.gz scala-bbd03b26f1eeba5abf495f5e745c6623f0cc05b7.tar.bz2 scala-bbd03b26f1eeba5abf495f5e745c6623f0cc05b7.zip |
SI-7777 applyDynamic macro fails for nested application
Interplay between the insertApply desugaring and the invokeDynamic desugarings
is already quite brittle, but the real fun begins when macros crash the party.
The proposed patch enriches the `isDesugaredApply` check performed in
`mkInvoke`, the invokeDynamic desugarer, and makes sure that everything
is safe and sound in the macroland.
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/t7777.check | 7 | ||||
-rw-r--r-- | test/files/run/t7777/Macros_1.scala | 17 | ||||
-rw-r--r-- | test/files/run/t7777/Test_2.scala | 6 |
3 files changed, 30 insertions, 0 deletions
diff --git a/test/files/run/t7777.check b/test/files/run/t7777.check new file mode 100644 index 0000000000..162ff2d2a2 --- /dev/null +++ b/test/files/run/t7777.check @@ -0,0 +1,7 @@ +foo(1, 2) +bar(4, 5) +foo(3) +bar(7) +apply(6) +apply(9) +foo(8) diff --git a/test/files/run/t7777/Macros_1.scala b/test/files/run/t7777/Macros_1.scala new file mode 100644 index 0000000000..459ab3edbb --- /dev/null +++ b/test/files/run/t7777/Macros_1.scala @@ -0,0 +1,17 @@ +import scala.language.experimental.macros +import scala.language.dynamics +import scala.reflect.macros.WhiteboxContext + +class DynMacro extends Dynamic { + def applyDynamic(s: String)(xs: Any*): DynMacro = + macro DynMacro.applyDynamicMacro +} + +object DynMacro extends DynMacro { + def applyDynamicMacro(c: WhiteboxContext)(s: c.Expr[String])(xs: c.Expr[Any]*): c.Expr[DynMacro] = { + import c.universe._ + val Literal(Constant(n: String)) = s.tree + val args = xs.map(_.tree.toString).mkString("(", ", ", ")") + c.Expr(q"println(${ n + args }); ${c.prefix.tree}") + } +}
\ No newline at end of file diff --git a/test/files/run/t7777/Test_2.scala b/test/files/run/t7777/Test_2.scala new file mode 100644 index 0000000000..1fe8b63bab --- /dev/null +++ b/test/files/run/t7777/Test_2.scala @@ -0,0 +1,6 @@ +object Test extends App { + DynMacro.foo(1, 2) // prints "foo(1, 2)" + DynMacro.foo(3).bar(4, 5) // prints "bar(4, 5)", then "foo(3)" + DynMacro(6).bar(7) // prints "bar(7)", then "apply(6)" + DynMacro.foo(8)(9) // Fails! +}
\ No newline at end of file |