Skip to content

Commit 36fde5d

Browse files
committed
Fix ListBuffer.insertAfter, used in patchInPlace
If the new elements are added to the end, `last0` needs to be updated. `insertAfter` is used in `patchInPlace` and `insertAll`, but the bug didn't manifest for `insertAll` because it delegates to `addAll` when adding to the end.
1 parent 93528af commit 36fde5d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

library/src/scala/collection/mutable/ListBuffer.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class ListBuffer[A]
4646
@transient private[this] var mutationCount: Int = 0
4747

4848
private var first: List[A] = Nil
49-
private var last0: ::[A] = null
49+
private var last0: ::[A] = null // last element (`last0` just because the name `last` is already taken)
5050
private[this] var aliased = false
5151
private[this] var len = 0
5252

@@ -244,6 +244,7 @@ class ListBuffer[A]
244244
val follow = getNext(prev)
245245
if (prev eq null) first = fresh.first else prev.next = fresh.first
246246
fresh.last0.next = follow
247+
if (follow.isEmpty) last0 = fresh.last0
247248
len += fresh.length
248249
}
249250
}

0 commit comments

Comments
 (0)