From 26a86793596c331ec19a8a584c6ff66d8d2acaef Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Fri, 2 Aug 2013 14:27:42 +0200 Subject: currentRun.compiles now correctly works in toolboxes Another random bug uncovered and extinguished when hacking macro annots. --- test/files/run/toolbox_current_run_compiles.check | 2 ++ test/files/run/toolbox_current_run_compiles.scala | 28 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 test/files/run/toolbox_current_run_compiles.check create mode 100644 test/files/run/toolbox_current_run_compiles.scala (limited to 'test') diff --git a/test/files/run/toolbox_current_run_compiles.check b/test/files/run/toolbox_current_run_compiles.check new file mode 100644 index 0000000000..da29283aaa --- /dev/null +++ b/test/files/run/toolbox_current_run_compiles.check @@ -0,0 +1,2 @@ +true +false diff --git a/test/files/run/toolbox_current_run_compiles.scala b/test/files/run/toolbox_current_run_compiles.scala new file mode 100644 index 0000000000..b48c998e64 --- /dev/null +++ b/test/files/run/toolbox_current_run_compiles.scala @@ -0,0 +1,28 @@ +package pkg { + import scala.reflect.macros.Context + import scala.language.experimental.macros + + object Macros { + def impl[T: c.WeakTypeTag](c: Context) = { + import c.universe._ + val sym = c.weakTypeOf[T].typeSymbol + val g = c.universe.asInstanceOf[scala.tools.nsc.Global] + c.Expr[Boolean](Literal(Constant(g.currentRun.compiles(sym.asInstanceOf[g.Symbol])))) + } + def compiles[T] = macro impl[T] + } +} + +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{universe => ru} +import scala.tools.reflect.ToolBox + +object Test extends App { + val cm = ru.runtimeMirror(getClass.getClassLoader) + val toolbox = cm.mkToolBox() + toolbox.eval(toolbox.parse("""{ + class C + println(pkg.Macros.compiles[C]) + println(pkg.Macros.compiles[Object]) + }""")) +} \ No newline at end of file -- cgit v1.2.3