From 43d3eec9fd3656b8ed0746a25c0a1ce0e9e74353 Mon Sep 17 00:00:00 2001 From: Jan Bessai Date: Sun, 23 Aug 2015 12:11:58 +0200 Subject: SI-6636 Fix macro expansion in toolboxes --- test/files/run/toolbox_expand_macro.check | 1 + test/files/run/toolbox_expand_macro.scala | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 test/files/run/toolbox_expand_macro.check create mode 100644 test/files/run/toolbox_expand_macro.scala (limited to 'test/files/run') diff --git a/test/files/run/toolbox_expand_macro.check b/test/files/run/toolbox_expand_macro.check new file mode 100644 index 0000000000..d81cc0710e --- /dev/null +++ b/test/files/run/toolbox_expand_macro.check @@ -0,0 +1 @@ +42 diff --git a/test/files/run/toolbox_expand_macro.scala b/test/files/run/toolbox_expand_macro.scala new file mode 100644 index 0000000000..a52e449168 --- /dev/null +++ b/test/files/run/toolbox_expand_macro.scala @@ -0,0 +1,23 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{universe => ru} +import scala.reflect.runtime.{currentMirror => cm} +import scala.tools.reflect.{ToolBox} + +object Test extends App { + val toolBox = cm.mkToolBox() + val x = 21 + val runtimeMacro = + q"""object RuntimeMacro { + import scala.reflect.macros.whitebox.Context + import scala.language.experimental.macros + + def add(y: Int): Int = macro addImpl + def addImpl(c: Context)(y: c.Expr[Int]): c.Expr[Int] = { + import c.universe._ + val x = $x + c.Expr[Int](q"$$x + $$y") + } + }""" + val s = toolBox.define(runtimeMacro) + println(toolBox.eval(q"$s.add(21)")) +} -- cgit v1.2.3