Skip to content

Commit ec4e74a

Browse files
Backport "Deduplicate patches before applying them to sources" to 3.7.4 (#24221)
Backports #24215 to the 3.7.4. PR submitted by the release tooling. [skip ci]
2 parents 39ebf6b + d6cf057 commit ec4e74a

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-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")

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class CompilationTests {
8989
compileFile("tests/rewrites/implicit-to-given.scala", defaultOptions.and("-rewrite", "-Yimplicit-to-given")),
9090
compileFile("tests/rewrites/i22792.scala", defaultOptions.and("-rewrite")),
9191
compileFile("tests/rewrites/i23449.scala", defaultOptions.and("-rewrite", "-source:3.4-migration")),
92+
compileFile("tests/rewrites/i24213.scala", defaultOptions.and("-rewrite", "-source:3.4-migration")),
9293
).checkRewrites()
9394
}
9495

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)