summaryrefslogtreecommitdiff
path: root/test/files/run/t7570b.scala
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2013-06-19 16:33:19 +0200
committerEugene Burmako <xeno.by@gmail.com>2014-01-24 09:18:04 +0300
commit1d53b2ba45cba536c3369e7b8c300666c603d460 (patch)
treec8d4cc7bb166b776ebc70c7696d82cad9e9f4194 /test/files/run/t7570b.scala
parentf22ddce265e8622e95f5e9cab4d38168bf2c3bf8 (diff)
downloadscala-1d53b2ba45cba536c3369e7b8c300666c603d460.tar.gz
scala-1d53b2ba45cba536c3369e7b8c300666c603d460.tar.bz2
scala-1d53b2ba45cba536c3369e7b8c300666c603d460.zip
SI-7570 top-level codegen for toolboxes
Provides a way to inject top-level classes, traits and modules into toolbox universes. Previously that was impossible, because compile and eval both wrap their arguments into an enclosing method of a synthetic module, which makes it impossible to later on refer to any definitions from the outside.
Diffstat (limited to 'test/files/run/t7570b.scala')
-rw-r--r--test/files/run/t7570b.scala17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/files/run/t7570b.scala b/test/files/run/t7570b.scala
new file mode 100644
index 0000000000..f1db193186
--- /dev/null
+++ b/test/files/run/t7570b.scala
@@ -0,0 +1,17 @@
+import scala.reflect.runtime.universe._
+import scala.reflect.runtime.{currentMirror => cm}
+import scala.tools.reflect.{ToolBox, ToolBoxError}
+import definitions._
+import Flag._
+
+object Test extends App {
+ val tb = cm.mkToolBox()
+ val msg = build.newFreeTerm("msg", "C")
+ build.setTypeSignature(msg, typeOf[String])
+ try {
+ val csym = tb.define(q"""class C { override def toString = $msg }""")
+ println(tb.eval(q"new $csym"))
+ } catch {
+ case ToolBoxError(message, _) => println(s"compilation failed: $message")
+ }
+} \ No newline at end of file