diff options
author | Josh Suereth <joshua.suereth@gmail.com> | 2012-09-05 14:15:01 -0400 |
---|---|---|
committer | Josh Suereth <joshua.suereth@gmail.com> | 2012-09-06 09:32:17 -0400 |
commit | 93d3cc703806bec34c4ef0c7817239966363c193 (patch) | |
tree | ed2834b1ba8df37c4e82462c541aaec9c230c278 | |
parent | 2355b656e030a7b968aa02de9a688f565b147581 (diff) | |
download | scala-93d3cc703806bec34c4ef0c7817239966363c193.tar.gz scala-93d3cc703806bec34c4ef0c7817239966363c193.tar.bz2 scala-93d3cc703806bec34c4ef0c7817239966363c193.zip |
Fixes SI-6271 - Missing isEmpty override for views.
GenIterableView didn't override isEmpty for views to look at *filtered* iterator, but was instead pulling
unfiltered iterator and causing issues. Chalk up another bizzare bug to lack of insight/visibility into
linearization and what havoc overriding new methods can spew on our library.
-rw-r--r-- | src/library/scala/collection/GenIterableViewLike.scala | 1 | ||||
-rw-r--r-- | test/files/run/t6271.scala | 32 |
2 files changed, 33 insertions, 0 deletions
diff --git a/src/library/scala/collection/GenIterableViewLike.scala b/src/library/scala/collection/GenIterableViewLike.scala index 9e3927eaf4..142561df20 100644 --- a/src/library/scala/collection/GenIterableViewLike.scala +++ b/src/library/scala/collection/GenIterableViewLike.scala @@ -25,6 +25,7 @@ self => def iterator: Iterator[B] override def foreach[U](f: B => U): Unit = iterator foreach f override def toString = viewToString + override def isEmpty = !iterator.hasNext } trait EmptyView extends Transformed[Nothing] with super.EmptyView { diff --git a/test/files/run/t6271.scala b/test/files/run/t6271.scala new file mode 100644 index 0000000000..8ebf7ad8b5 --- /dev/null +++ b/test/files/run/t6271.scala @@ -0,0 +1,32 @@ +object Test extends App { + def filterIssue = { + val viewed : Iterable[Iterable[Int]] = List(List(0).view).view + val filtered = viewed flatMap { x => List( x filter (_ > 0) ) } + filtered.iterator.toIterable.flatten + } + def takenIssue = { + val viewed : Iterable[Iterable[Int]] = List(List(0).view).view + val filtered = viewed flatMap { x => List( x take 0 ) } + filtered.iterator.toIterable.flatten + } + def droppedIssue = { + val viewed : Iterable[Iterable[Int]] = List(List(0).view).view + val filtered = viewed flatMap { x => List( x drop 1 ) } + filtered.iterator.toIterable.flatten + } + def flatMappedIssue = { + val viewed : Iterable[Iterable[Int]] = List(List(0).view).view + val filtered = viewed flatMap { x => List( x flatMap (_ => List()) ) } + filtered.iterator.toIterable.flatten + } + def slicedIssue = { + val viewed : Iterable[Iterable[Int]] = List(List(0).view).view + val filtered = viewed flatMap { x => List( x slice (2,3) ) } + filtered.iterator.toIterable.flatten + } + filterIssue + takenIssue + droppedIssue + flatMappedIssue + slicedIssue +} |