summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2014-07-03 17:02:34 +0200
committerEugene Burmako <xeno.by@gmail.com>2014-07-03 18:50:15 +0200
commit36379cf8af8e0bb92f7a399fe2c8e1cb05b31fc9 (patch)
treef2a55323e644be25c68b04b76ffb8a862773476e /test
parent300db2a1e3eefc2a6ed379c870bc7da42a26e69a (diff)
downloadscala-36379cf8af8e0bb92f7a399fe2c8e1cb05b31fc9.tar.gz
scala-36379cf8af8e0bb92f7a399fe2c8e1cb05b31fc9.tar.bz2
scala-36379cf8af8e0bb92f7a399fe2c8e1cb05b31fc9.zip
[backport] transformers no longer ignore UnApply.fun
Backports 7122560063 and 4133eb8454 from the 2.11.x branch
Diffstat (limited to 'test')
-rw-r--r--test/files/run/t7871.check1
-rw-r--r--test/files/run/t7871/Macros_1.scala43
-rw-r--r--test/files/run/t7871/Test_2.scala6
3 files changed, 50 insertions, 0 deletions
diff --git a/test/files/run/t7871.check b/test/files/run/t7871.check
new file mode 100644
index 0000000000..ce6efd812d
--- /dev/null
+++ b/test/files/run/t7871.check
@@ -0,0 +1 @@
+(SomeTree,SomeTree)
diff --git a/test/files/run/t7871/Macros_1.scala b/test/files/run/t7871/Macros_1.scala
new file mode 100644
index 0000000000..2943445ff8
--- /dev/null
+++ b/test/files/run/t7871/Macros_1.scala
@@ -0,0 +1,43 @@
+import scala.reflect.macros.Context
+import scala.language.experimental.macros
+
+trait Tree
+case object SomeTree extends Tree
+
+object NewQuasiquotes {
+ implicit class QuasiquoteInterpolation(c: StringContext) {
+ object nq {
+ def unapply(t: Tree): Any = macro QuasiquoteMacros.unapplyImpl
+ }
+ }
+}
+
+object QuasiquoteMacros {
+ def unapplyImpl(c: Context)(t: c.Expr[Tree]) = {
+ import c.universe._
+ import Flag._
+ // q"""
+ // new {
+ // def unapply(t: Tree) = t match {
+ // case SomeTree => Some((SomeTree, SomeTree))
+ // case _ => None
+ // }
+ // }.unapply($t)
+ // """
+ c.Expr[Any](Apply(
+ Select(
+ Block(List(
+ ClassDef(Modifiers(FINAL), newTypeName("$anon"), List(),
+ Template(List(Select(Ident(newTermName("scala")), newTypeName("AnyRef"))), 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("unapply"), List(), List(List(ValDef(Modifiers(PARAM), newTermName("t"), Ident(newTypeName("Tree")), EmptyTree))), TypeTree(),
+ Match(
+ Ident(newTermName("t")), List(
+ CaseDef(Ident(newTermName("SomeTree")), EmptyTree, Apply(Ident(newTermName("Some")), List(Apply(Select(Ident(newTermName("scala")), newTermName("Tuple2")), List(Ident(newTermName("SomeTree")), Ident(newTermName("SomeTree"))))))),
+ CaseDef(Ident(nme.WILDCARD), EmptyTree, Ident(newTermName("None")))))))))),
+ Apply(Select(New(Ident(newTypeName("$anon"))), nme.CONSTRUCTOR), List())),
+ newTermName("unapply")),
+ List(t.tree)))
+ }
+}
diff --git a/test/files/run/t7871/Test_2.scala b/test/files/run/t7871/Test_2.scala
new file mode 100644
index 0000000000..3a0b68b568
--- /dev/null
+++ b/test/files/run/t7871/Test_2.scala
@@ -0,0 +1,6 @@
+object Test extends App {
+ import NewQuasiquotes._
+ SomeTree match {
+ case nq"$x + $y" => println((x, y))
+ }
+}