diff options
author | Paul Phillips <paulp@improving.org> | 2013-03-12 19:16:23 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-03-12 19:16:23 -0700 |
commit | b7b4f877326acd6a8a24ff60fa1638cc18143c45 (patch) | |
tree | 2695f167af5f522977b285bbb4bfc5a39c432539 /test/files/run | |
parent | 7d0cb1f0e2c254ccc071fcd8a057c67065682a0f (diff) | |
parent | a4fb77332cf641b023b46af5533b6007948b766e (diff) | |
download | scala-b7b4f877326acd6a8a24ff60fa1638cc18143c45.tar.gz scala-b7b4f877326acd6a8a24ff60fa1638cc18143c45.tar.bz2 scala-b7b4f877326acd6a8a24ff60fa1638cc18143c45.zip |
Merge pull request #2234 from scalamacros/ticket/7240
SI-7240 fixes language feature lookup
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/t7240.check | 0 | ||||
-rw-r--r-- | test/files/run/t7240/Macros_1.scala | 48 | ||||
-rw-r--r-- | test/files/run/t7240/Test_2.scala | 3 |
3 files changed, 51 insertions, 0 deletions
diff --git a/test/files/run/t7240.check b/test/files/run/t7240.check new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/test/files/run/t7240.check diff --git a/test/files/run/t7240/Macros_1.scala b/test/files/run/t7240/Macros_1.scala new file mode 100644 index 0000000000..6465e18760 --- /dev/null +++ b/test/files/run/t7240/Macros_1.scala @@ -0,0 +1,48 @@ +package bakery + +import scala.language.experimental.macros +import scala.reflect.macros.Context + +trait FailureCake { + implicit def liftAnyFails[T: Manifest]: Any = ??? + + // This works + // implicit def liftAny[T]: Any = ??? +} + +object Bakery { + + def failure: Any = macro failureImpl + def failureImpl(c: Context): c.Expr[Any] = { + import c.universe._ + + def dslTrait(dslName: String) = { + val names = dslName.split("\\.").toList.reverse + assert(names.length >= 1, "DSL trait name must be in the valid format. DSL trait name is " + dslName) + + val tpeName = newTypeName(names.head) + names.tail.reverse match { + case head :: tail ⇒ + Select(tail.foldLeft[Tree](Ident(newTermName(head)))((tree, name) ⇒ Select(tree, newTermName(name))), tpeName) + case Nil ⇒ + Ident(tpeName) + } + } + + def composeDSL(transformedBody: Tree) = + ClassDef(Modifiers(), newTypeName("eval"), List(), Template( + List(dslTrait("bakery.FailureCake")), + emptyValDef, + List( + DefDef(Modifiers(), nme.CONSTRUCTOR, List(), List(List()), TypeTree(), + Block(List(Apply(Select(Super(This(tpnme.EMPTY), tpnme.EMPTY), nme.CONSTRUCTOR), List())), Literal(Constant(())))), + DefDef(Modifiers(), newTermName("main"), List(), List(List()), Ident(newTypeName("Any")), transformedBody)))) + + def constructor = Apply(Select(New(Ident(newTypeName("eval"))), nme.CONSTRUCTOR), List()) + + c.eval(c.Expr[Any]( + c.resetAllAttrs(Block(composeDSL(Literal(Constant(1))), constructor)))) + + c.Expr[Any](Literal(Constant(1))) + } +}
\ No newline at end of file diff --git a/test/files/run/t7240/Test_2.scala b/test/files/run/t7240/Test_2.scala new file mode 100644 index 0000000000..2450bdabf9 --- /dev/null +++ b/test/files/run/t7240/Test_2.scala @@ -0,0 +1,3 @@ +object Test extends App { + bakery.Bakery.failure +}
\ No newline at end of file |