summaryrefslogtreecommitdiff
path: root/test/files/run/t6992/Macros_1.scala
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2013-12-17 03:56:52 -0800
committerEugene Burmako <xeno.by@gmail.com>2013-12-17 03:56:52 -0800
commitb5ef79f2f8bc010220d2920a890352d96ad84b45 (patch)
treefd6b0985debc9348bdc8df1f7b3629415974e5cb /test/files/run/t6992/Macros_1.scala
parentdbe7a366c994fe359edc368bfcd8a6a35a00e0da (diff)
parentca2dbe55eb55ec0d5461a62f5783ab1f1ebb4818 (diff)
downloadscala-b5ef79f2f8bc010220d2920a890352d96ad84b45.tar.gz
scala-b5ef79f2f8bc010220d2920a890352d96ad84b45.tar.bz2
scala-b5ef79f2f8bc010220d2920a890352d96ad84b45.zip
Merge pull request #3236 from xeno-by/topic/wildbox-macros
(2.11.0-M8) whitebox macros are now first typechecked against outerPt
Diffstat (limited to 'test/files/run/t6992/Macros_1.scala')
-rw-r--r--test/files/run/t6992/Macros_1.scala75
1 files changed, 75 insertions, 0 deletions
diff --git a/test/files/run/t6992/Macros_1.scala b/test/files/run/t6992/Macros_1.scala
new file mode 100644
index 0000000000..25566dddbf
--- /dev/null
+++ b/test/files/run/t6992/Macros_1.scala
@@ -0,0 +1,75 @@
+import scala.language.experimental.macros
+import scala.reflect.macros.Context
+
+object Macros {
+ def foo(name: String): Any = macro foo_impl
+ def foo_impl(c: Context)(name: c.Expr[String]) = {
+ import c.universe._
+
+ val Literal(Constant(lit: String)) = name.tree
+ val anon = newTypeName(c.fresh)
+
+ c.Expr(Block(
+ ClassDef(
+ Modifiers(Flag.FINAL), anon, Nil, Template(
+ Nil, noSelfType, List(
+ DefDef(Modifiers(), nme.CONSTRUCTOR, List(), List(List()), TypeTree(), Block(List(pendingSuperCall), Literal(Constant(())))),
+ TypeDef(Modifiers(), TypeName(lit), Nil, TypeTree(typeOf[Int]))
+ )
+ )
+ ),
+ Apply(Select(New(Ident(anon)), nme.CONSTRUCTOR), Nil)
+ ))
+ }
+
+ def bar(name: String): Any = macro bar_impl
+ def bar_impl(c: Context)(name: c.Expr[String]) = {
+ import c.universe._
+
+ val Literal(Constant(lit: String)) = name.tree
+ val anon = newTypeName(c.fresh)
+
+ c.Expr(Block(
+ ClassDef(
+ Modifiers(Flag.FINAL), anon, Nil, Template(
+ Nil, noSelfType, List(
+ DefDef(Modifiers(), nme.CONSTRUCTOR, List(), List(List()), TypeTree(), Block(List(pendingSuperCall), Literal(Constant(())))),
+ DefDef(
+ Modifiers(), TermName(lit), Nil, Nil, TypeTree(),
+ c.literal(42).tree
+ )
+ )
+ )
+ ),
+ Apply(Select(New(Ident(anon)), nme.CONSTRUCTOR), Nil)
+ ))
+ }
+
+ def baz(name: String): Any = macro baz_impl
+ def baz_impl(c: Context)(name: c.Expr[String]) = {
+ import c.universe._
+
+ val Literal(Constant(lit: String)) = name.tree
+ val anon = newTypeName(c.fresh)
+ val wrapper = newTypeName(c.fresh)
+
+ c.Expr(Block(
+ ClassDef(
+ Modifiers(), anon, Nil, Template(
+ Nil, emptyValDef, List(
+ DefDef(Modifiers(), nme.CONSTRUCTOR, List(), List(List()), TypeTree(), Block(List(pendingSuperCall), Literal(Constant(())))),
+ DefDef(
+ Modifiers(), TermName(lit), Nil, Nil, TypeTree(),
+ c.literal(42).tree
+ )
+ )
+ )
+ ),
+ ClassDef(
+ Modifiers(Flag.FINAL), wrapper, Nil,
+ Template(Ident(anon) :: Nil, noSelfType, DefDef(Modifiers(), nme.CONSTRUCTOR, List(), List(List()), TypeTree(), Block(List(pendingSuperCall), Literal(Constant(())))) :: Nil)
+ ),
+ Apply(Select(New(Ident(wrapper)), nme.CONSTRUCTOR), Nil)
+ ))
+ }
+} \ No newline at end of file