diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2013-01-07 07:42:38 +0300 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2013-01-09 08:10:46 +0100 |
commit | 66acf364ae3003dd1abb4eeb8759afc6e12aa1a1 (patch) | |
tree | 853fc3cf39bd34ec32887843fb98f05bad8f1fb7 /test/files/run/macro-expand-unapply-a | |
parent | d17e3fc29cd48a3d4cbbbfc1fc9eb021d787d4d7 (diff) | |
download | scala-66acf364ae3003dd1abb4eeb8759afc6e12aa1a1.tar.gz scala-66acf364ae3003dd1abb4eeb8759afc6e12aa1a1.tar.bz2 scala-66acf364ae3003dd1abb4eeb8759afc6e12aa1a1.zip |
SI-5903 extractor macros do work
Apparently it is already possible to use macros to customize pattern
matching as described in the comments to the aforementioned JIRA issue.
What's even better - with the incoming addition of c.introduceTopLevel
it becomes possible to generate arbitrarily complex unappliers, even
with heterogeneous types of arguments varying from expansion to expansion
Diffstat (limited to 'test/files/run/macro-expand-unapply-a')
-rw-r--r-- | test/files/run/macro-expand-unapply-a/Impls_Macros_1.scala | 15 | ||||
-rw-r--r-- | test/files/run/macro-expand-unapply-a/Test_2.scala | 6 |
2 files changed, 21 insertions, 0 deletions
diff --git a/test/files/run/macro-expand-unapply-a/Impls_Macros_1.scala b/test/files/run/macro-expand-unapply-a/Impls_Macros_1.scala new file mode 100644 index 0000000000..61d6345f16 --- /dev/null +++ b/test/files/run/macro-expand-unapply-a/Impls_Macros_1.scala @@ -0,0 +1,15 @@ +import scala.reflect.macros.Context + +object Helper { + def unapplySeq[T](x: List[T]): Option[Seq[T]] = List.unapplySeq[T](x) +} + +object Macros { + def impl[T: c.WeakTypeTag](c: Context)(x: c.Expr[List[T]]) = { + c.universe.reify(Helper.unapplySeq(x.splice)) + } + + object UnapplyMacro { + def unapplySeq[T](x: List[T]): Option[Seq[T]] = macro impl[T] + } +}
\ No newline at end of file diff --git a/test/files/run/macro-expand-unapply-a/Test_2.scala b/test/files/run/macro-expand-unapply-a/Test_2.scala new file mode 100644 index 0000000000..6169d86b19 --- /dev/null +++ b/test/files/run/macro-expand-unapply-a/Test_2.scala @@ -0,0 +1,6 @@ +import Macros._ + +object Test extends App { + List(1, 2) match { case UnapplyMacro(x, y) => println((x, y)) } + List(1, 2, 3) match { case UnapplyMacro(x, y, z) => println((x, y, z)) } +}
\ No newline at end of file |