diff options
author | Denys Shabalin <denys.shabalin@typesafe.com> | 2014-02-24 18:35:59 +0100 |
---|---|---|
committer | Denys Shabalin <denys.shabalin@typesafe.com> | 2014-02-28 11:28:38 +0100 |
commit | 51b8e6c020d39393c471dcfee389c5f0f7510afd (patch) | |
tree | 75eac002632749d6fd32d31101934a7f9b71da37 /src | |
parent | 13e7b8112fb412bb3ed29716409087aed0f2a7e4 (diff) | |
download | scala-51b8e6c020d39393c471dcfee389c5f0f7510afd.tar.gz scala-51b8e6c020d39393c471dcfee389c5f0f7510afd.tar.bz2 scala-51b8e6c020d39393c471dcfee389c5f0f7510afd.zip |
SI-8285 use correct kind of map for quasiquote positions
Previously mutable.ListMap was used with assumption that it preserved
order of inserted elements (but it doesn't). Surprisingly logic that
assumed ordered elements worked mosly fine on unordered ones. I guess
two bugs can cancel each other out.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/reflect/quasiquotes/Parsers.scala | 10 | ||||
-rw-r--r-- | src/compiler/scala/tools/reflect/quasiquotes/Placeholders.scala | 6 |
2 files changed, 7 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/reflect/quasiquotes/Parsers.scala b/src/compiler/scala/tools/reflect/quasiquotes/Parsers.scala index 3b93a8933d..b22e0b0e82 100644 --- a/src/compiler/scala/tools/reflect/quasiquotes/Parsers.scala +++ b/src/compiler/scala/tools/reflect/quasiquotes/Parsers.scala @@ -30,15 +30,15 @@ trait Parsers { self: Quasiquotes => def correspondingPosition(offset: Int): Position = { val posMapList = posMap.toList - def containsOffset(start: Int, end: Int) = start <= offset && offset <= end + def containsOffset(start: Int, end: Int) = start <= offset && offset < end def fallbackPosition = posMapList match { case (pos1, (start1, end1)) :: _ if start1 > offset => pos1 - case _ :+ ((pos2, (start2, end2))) if offset > end2 => pos2.withPoint(pos2.point + (end2 - start2)) + case _ :+ ((pos2, (start2, end2))) if end2 <= offset => pos2.withPoint(pos2.point + (end2 - start2)) } posMapList.sliding(2).collect { - case (pos1, (start1, end1)) :: _ if containsOffset(start1, end1) => (pos1, offset - start1) - case (pos1, (_, end1)) :: (_, (start2, _)) :: _ if containsOffset(end1, start2) => (pos1, end1) - case _ :: (pos2, (start2, end2)) :: _ if containsOffset(start2, end2) => (pos2, offset - start2) + case (pos1, (start1, end1)) :: _ if containsOffset(start1, end1) => (pos1, offset - start1) + case (pos1, (start1, end1)) :: (pos2, (start2, _)) :: _ if containsOffset(end1, start2) => (pos1, end1 - start1) + case _ :: (pos2, (start2, end2)) :: _ if containsOffset(start2, end2) => (pos2, offset - start2) }.map { case (pos, offset) => pos.withPoint(pos.point + offset) }.toList.headOption.getOrElse(fallbackPosition) diff --git a/src/compiler/scala/tools/reflect/quasiquotes/Placeholders.scala b/src/compiler/scala/tools/reflect/quasiquotes/Placeholders.scala index 5986758c2b..b287971815 100644 --- a/src/compiler/scala/tools/reflect/quasiquotes/Placeholders.scala +++ b/src/compiler/scala/tools/reflect/quasiquotes/Placeholders.scala @@ -17,7 +17,7 @@ trait Placeholders { self: Quasiquotes => // Step 1: Transform Scala source with holes into vanilla Scala source - lazy val posMap = mutable.ListMap[Position, (Int, Int)]() + lazy val posMap = mutable.LinkedHashMap[Position, (Int, Int)]() lazy val code = { val sb = new StringBuilder() val sessionSuffix = randomUUID().toString.replace("-", "").substring(0, 8) + "$" @@ -40,9 +40,7 @@ trait Placeholders { self: Quasiquotes => val iargs = method match { case nme.apply => args - case nme.unapply => - val (dummy @ Ident(nme.SELECTOR_DUMMY)) :: Nil = args - internal.subpatterns(dummy).get + case nme.unapply => internal.subpatterns(args.head).get case _ => global.abort("unreachable") } |