Skip to content

Commit 1dd5e33

Browse files
committed
[nomerge] Export underlying on non-copying conversion
Any `TraversableForwarder` method with the danger of returning `underlying` itself needs to go through `toList` (which marks the underlying list as needing to be copied on the next mutation). Notice that `toStream` is also affected since `List#toStream` builds the result lazily. Fixes scala/bug#11869
1 parent 10612a8 commit 1dd5e33

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,18 @@ final class ListBuffer[A]
306306
def result: List[A] = toList
307307

308308
/** Converts this buffer to a list. Takes constant time. The buffer is
309-
* copied lazily, the first time it is mutated.
309+
* copied lazily the first time it is mutated.
310310
*/
311311
override def toList: List[A] = {
312312
exported = !isEmpty
313313
start
314314
}
315315

316+
// scala/bug#11869
317+
override def toSeq: collection.Seq[A] = toList
318+
override def toIterable: collection.Iterable[A] = toList
319+
override def toStream: immutable.Stream[A] = toList.toStream // mind the laziness
320+
316321
// New methods in ListBuffer
317322

318323
/** Prepends the elements of this buffer to a given list

0 commit comments

Comments
 (0)