diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2013-10-02 17:22:17 +0200 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-11-12 18:40:02 -0800 |
commit | f83296552aa80faf8a9350131c0448bc05b34c96 (patch) | |
tree | 181a29f647609ba4d9cd8566fcde96c603d61259 /test/files/neg/macro-blackbox-extractor | |
parent | 0d5c2f76ea30c6a45471dac635f035e931075453 (diff) | |
download | scala-f83296552aa80faf8a9350131c0448bc05b34c96.tar.gz scala-f83296552aa80faf8a9350131c0448bc05b34c96.tar.bz2 scala-f83296552aa80faf8a9350131c0448bc05b34c96.zip |
blackbox restriction #4: can't customize pattern matching
When an application of a blackbox macro is used as an extractor in a
pattern match, it triggers an unconditional compiler error,
preventing customizations of pattern matching implemented with macros.
Diffstat (limited to 'test/files/neg/macro-blackbox-extractor')
-rw-r--r-- | test/files/neg/macro-blackbox-extractor/Macros_1.scala | 21 | ||||
-rw-r--r-- | test/files/neg/macro-blackbox-extractor/Test_2.scala | 5 |
2 files changed, 26 insertions, 0 deletions
diff --git a/test/files/neg/macro-blackbox-extractor/Macros_1.scala b/test/files/neg/macro-blackbox-extractor/Macros_1.scala new file mode 100644 index 0000000000..5c7748bec9 --- /dev/null +++ b/test/files/neg/macro-blackbox-extractor/Macros_1.scala @@ -0,0 +1,21 @@ +import scala.reflect.macros.BlackboxContext +import language.experimental.macros + +object Extractor { + def unapply(x: Int) = macro Macros.unapplyImpl +} + +object Macros { + def unapplyImpl(c: BlackboxContext)(x: c.Tree) = { + import c.universe._ + q""" + new { + class Match(x: Int) { + def isEmpty = false + def get = x + } + def unapply(x: Int) = new Match(x) + }.unapply($x) + """ + } +} diff --git a/test/files/neg/macro-blackbox-extractor/Test_2.scala b/test/files/neg/macro-blackbox-extractor/Test_2.scala new file mode 100644 index 0000000000..41be6f9767 --- /dev/null +++ b/test/files/neg/macro-blackbox-extractor/Test_2.scala @@ -0,0 +1,5 @@ +object Test extends App { + 42 match { + case Extractor(x) => println(x) + } +} |