diff options
author | Rex Kerr <ichoran@gmail.com> | 2014-01-16 08:23:24 -0800 |
---|---|---|
committer | Rex Kerr <ichoran@gmail.com> | 2014-02-12 19:27:47 -0800 |
commit | 509bd09a994365065550bcac4c821b15b8c6dbf0 (patch) | |
tree | 391151bfd0254b6c0ff68f1435d3fd4e1c49818c /test/files | |
parent | 9c4a6e3ed7624892f46948c1c0fb57d7d5b3346e (diff) | |
download | scala-509bd09a994365065550bcac4c821b15b8c6dbf0.tar.gz scala-509bd09a994365065550bcac4c821b15b8c6dbf0.tar.bz2 scala-509bd09a994365065550bcac4c821b15b8c6dbf0.zip |
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).
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/run/t8153.check | 1 | ||||
-rw-r--r-- | test/files/run/t8153.scala | 14 |
2 files changed, 15 insertions, 0 deletions
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()) + } +} |