Skip to content

Commit 42ac2e1

Browse files
committed
Fix assert in Rewrites
`Iterator.sliding(2, 1)` returns a one-element result if the original iterator contains only one element, which makes it unpleasant to use for our task. Replaced by a fold.
1 parent d17ceb5 commit 42ac2e1

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/dotty/tools/dotc/rewrite/Rewrites.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ object Rewrites {
2323
def apply(cs: Array[Char]): Array[Char] = {
2424
val delta = pbuf.map(_.delta).sum
2525
val patches = pbuf.toList.sortBy(_.pos.start)
26-
patches.iterator.sliding(2, 1).foreach(ps =>
27-
assert(ps(0).pos.end <= ps(1).pos.start, s"overlapping patches: ${ps(0)} and ${ps(1)}"))
26+
if (patches.nonEmpty)
27+
patches reduceLeft {(p1, p2) =>
28+
assert(p1.pos.end <= p2.pos.start, s"overlapping patches: $p1 and $p2")
29+
p2
30+
}
2831
val ds = new Array[Char](cs.length + delta)
2932
def loop(ps: List[Patch], inIdx: Int, outIdx: Int): Unit = {
3033
def copy(upTo: Int): Int = {

0 commit comments

Comments
 (0)