diff options
Diffstat (limited to 'test/files/run/macro-rangepos-subpatterns/Macros_1.scala')
-rw-r--r-- | test/files/run/macro-rangepos-subpatterns/Macros_1.scala | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/files/run/macro-rangepos-subpatterns/Macros_1.scala b/test/files/run/macro-rangepos-subpatterns/Macros_1.scala new file mode 100644 index 0000000000..0f30862347 --- /dev/null +++ b/test/files/run/macro-rangepos-subpatterns/Macros_1.scala @@ -0,0 +1,18 @@ +import scala.reflect.macros.whitebox.Context +import language.experimental.macros + +object Extractor { + def unapply(x: Any): Any = macro unapplyImpl + def unapplyImpl(c: Context)(x: c.Tree) = { + import c.universe._ + import internal._ + val pos = subpatterns(x).get.head.pos + q""" + new { + def isEmpty = false + def get = ${"The width of the subpattern is: " + (pos.end - pos.start + 1)} + def unapply(x: Any) = this + }.unapply($x) + """ + } +} |