From 509bd09a994365065550bcac4c821b15b8c6dbf0 Mon Sep 17 00:00:00 2001 From: Rex Kerr Date: Thu, 16 Jan 2014 08:23:24 -0800 Subject: SI-8153 Mutation is hard, let's go shopping with an empty list Changed the implementation of iterator to be more robust to mutation of the underlying ListBuffer. Added a test to make sure bug is gone. Fixed an "unsafe" usage of ListBuffer.iterator in the compiler, and added a comment explaining the (new) policy for iterating over a changing ListBuffer. The compiler now uses a synchronized-wrapped ArrayBuffer instead of ListBuffer, as that makes the (custom) units Iterator more natural to write (and avoids O(n) lookups). --- test/files/run/t8153.check | 1 + test/files/run/t8153.scala | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 test/files/run/t8153.check create mode 100644 test/files/run/t8153.scala (limited to 'test') diff --git a/test/files/run/t8153.check b/test/files/run/t8153.check new file mode 100644 index 0000000000..0cfbf08886 --- /dev/null +++ b/test/files/run/t8153.check @@ -0,0 +1 @@ +2 diff --git a/test/files/run/t8153.scala b/test/files/run/t8153.scala new file mode 100644 index 0000000000..f9b223f974 --- /dev/null +++ b/test/files/run/t8153.scala @@ -0,0 +1,14 @@ +object Test { + def f() = { + val lb = scala.collection.mutable.ListBuffer[Int](1, 2) + val it = lb.iterator + if (it.hasNext) it.next + val xs = lb.toList + lb += 3 + it.mkString + } + + def main(args: Array[String]) { + println(f()) + } +} -- cgit v1.2.3