summaryrefslogtreecommitdiff
path: root/test/files/run/macro-toplevel/Macros_1.scala
diff options
context:
space:
mode:
Diffstat (limited to 'test/files/run/macro-toplevel/Macros_1.scala')
-rw-r--r--test/files/run/macro-toplevel/Macros_1.scala15
1 files changed, 15 insertions, 0 deletions
diff --git a/test/files/run/macro-toplevel/Macros_1.scala b/test/files/run/macro-toplevel/Macros_1.scala
new file mode 100644
index 0000000000..f681c86735
--- /dev/null
+++ b/test/files/run/macro-toplevel/Macros_1.scala
@@ -0,0 +1,15 @@
+import scala.reflect.macros.Context
+import language.experimental.macros
+
+object Macros {
+ def impl(c: Context) = {
+ import c.universe._
+ val msg = "I've been created from " + c.macroApplication
+ val Block(List(synthetic: ClassDef), _) = reify{ class SomeUniqueName { def hello = c.literal(msg).splice } }.tree
+ val ref = c.topLevelRef(synthetic.name) orElse c.introduceTopLevel(nme.EMPTY_PACKAGE_NAME.toString, synthetic)
+ c.Expr[String](Select(Apply(Select(New(ref), nme.CONSTRUCTOR), List()), TermName("hello")))
+ }
+
+ def foo = macro impl
+ def foo2 = macro impl
+}