Skip to content

Commit c5fc83f

Browse files
authored
Merge pull request #631 from scala/backport-lts-3.3-24215
Backport "Deduplicate patches before applying them to sources" to 3.3 LTS
2 parents 3b70155 + 7ed8e9f commit c5fc83f

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

compiler/src/dotty/tools/dotc/rewrites/Rewrites.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ object Rewrites {
4343
pbuf.filterInPlace(x => !p(x.span))
4444

4545
def apply(cs: Array[Char]): Array[Char] = {
46-
val delta = pbuf.map(_.delta).sum
47-
val patches = pbuf.toList.sortBy(_.span.start)
46+
val patches = pbuf.toList.distinct.sortBy(_.span.start)
47+
val delta = patches.map(_.delta).sum
4848
if (patches.nonEmpty)
4949
patches.reduceLeft {(p1, p2) =>
5050
assert(p1.span.end <= p2.span.start, s"overlapping patches in $source: $p1 and $p2")

tests/rewrites/i24213.check

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def Test =
2+
try ()
3+
catch {
4+
case x: Throwable if x.getMessage `contains` "error" => ???
5+
}

tests/rewrites/i24213.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def Test =
2+
try ()
3+
catch {
4+
case x: Throwable if x.getMessage contains "error" => ???
5+
}

0 commit comments

Comments
 (0)