summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2014-07-15 14:31:24 +0200
committerJason Zaugg <jzaugg@gmail.com>2014-07-15 14:31:24 +0200
commit2a137d00faddfc3c23ba52d5d0876e974d547798 (patch)
tree7fb950d12cc1bc5b1c8a888d0c017d5acdd347e1
parent87bba9418ca891c436f386207b3b9e70b4a64c71 (diff)
parent5ba2be24f82631f10d9163513204c5e44f445555 (diff)
downloadscala-2a137d00faddfc3c23ba52d5d0876e974d547798.tar.gz
scala-2a137d00faddfc3c23ba52d5d0876e974d547798.tar.bz2
scala-2a137d00faddfc3c23ba52d5d0876e974d547798.zip
Merge pull request #3844 from xeno-by/topic/rangepos-subpatterns
prevents c.internal.subpatterns from destroying rangeposes
-rw-r--r--src/reflect/scala/reflect/internal/Internals.scala2
-rw-r--r--test/files/run/macro-rangepos-subpatterns.check1
-rw-r--r--test/files/run/macro-rangepos-subpatterns.flags1
-rw-r--r--test/files/run/macro-rangepos-subpatterns/Macros_1.scala18
-rw-r--r--test/files/run/macro-rangepos-subpatterns/Test_2.scala5
5 files changed, 26 insertions, 1 deletions
diff --git a/src/reflect/scala/reflect/internal/Internals.scala b/src/reflect/scala/reflect/internal/Internals.scala
index e9916cf7d1..26f3bfd9d0 100644
--- a/src/reflect/scala/reflect/internal/Internals.scala
+++ b/src/reflect/scala/reflect/internal/Internals.scala
@@ -129,7 +129,7 @@ trait Internals extends api.Internals {
def typeBounds(lo: Type, hi: Type): TypeBounds = self.TypeBounds(lo, hi)
def boundedWildcardType(bounds: TypeBounds): BoundedWildcardType = self.BoundedWildcardType(bounds)
- def subpatterns(tree: Tree): Option[List[Tree]] = tree.attachments.get[SubpatternsAttachment].map(_.patterns.map(_.duplicate))
+ def subpatterns(tree: Tree): Option[List[Tree]] = tree.attachments.get[SubpatternsAttachment].map(_.patterns.map(duplicateAndKeepPositions))
type Decorators = MacroDecoratorApi
lazy val decorators: Decorators = new MacroDecoratorApi {
diff --git a/test/files/run/macro-rangepos-subpatterns.check b/test/files/run/macro-rangepos-subpatterns.check
new file mode 100644
index 0000000000..760e15d019
--- /dev/null
+++ b/test/files/run/macro-rangepos-subpatterns.check
@@ -0,0 +1 @@
+The width of the subpattern is: 2
diff --git a/test/files/run/macro-rangepos-subpatterns.flags b/test/files/run/macro-rangepos-subpatterns.flags
new file mode 100644
index 0000000000..fcf951d907
--- /dev/null
+++ b/test/files/run/macro-rangepos-subpatterns.flags
@@ -0,0 +1 @@
+-Yrangepos \ No newline at end of file
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)
+ """
+ }
+}
diff --git a/test/files/run/macro-rangepos-subpatterns/Test_2.scala b/test/files/run/macro-rangepos-subpatterns/Test_2.scala
new file mode 100644
index 0000000000..7b076e6632
--- /dev/null
+++ b/test/files/run/macro-rangepos-subpatterns/Test_2.scala
@@ -0,0 +1,5 @@
+object Test extends App {
+ 42 match {
+ case Extractor(a) => println(a)
+ }
+}