From 7a6905dc158a7a543ba3f4ddeeffe538580958d3 Mon Sep 17 00:00:00 2001 From: Grzegorz Kossakowski Date: Tue, 9 Oct 2012 15:45:35 -0700 Subject: SI-6440: Revert change to `TraversableLike.filterNot` Commit df9f470f14262b9b1002f022c2620d8c38835805 introduced a change to `TraversableLike.filterNot` which broke Stream implementation that does override `filter` implementation but does not override `filterNot` implementation. This shows clearly that reusing code for strict and non-strict collections is very problematic. Added a test-case covering this problem. Closes SI-6440. Review by @retronym. --- src/library/scala/collection/TraversableLike.scala | 7 +------ test/files/run/t6440.check | 1 + test/files/run/t6440.scala | 7 +++++++ 3 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 test/files/run/t6440.check create mode 100644 test/files/run/t6440.scala diff --git a/src/library/scala/collection/TraversableLike.scala b/src/library/scala/collection/TraversableLike.scala index ce0b130b86..7849f1c544 100644 --- a/src/library/scala/collection/TraversableLike.scala +++ b/src/library/scala/collection/TraversableLike.scala @@ -271,12 +271,7 @@ trait TraversableLike[+A, +Repr] extends Any * @return a new $coll consisting of all elements of this $coll that do not satisfy the given * predicate `p`. The order of the elements is preserved. */ - def filterNot(p: A => Boolean): Repr = { - val b = newBuilder - for (x <- this) - if (!p(x)) b += x - b.result - } + def filterNot(p: A => Boolean): Repr = filter(!p(_)) def collect[B, That](pf: PartialFunction[A, B])(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) diff --git a/test/files/run/t6440.check b/test/files/run/t6440.check new file mode 100644 index 0000000000..b5684daee4 --- /dev/null +++ b/test/files/run/t6440.check @@ -0,0 +1 @@ +Stream((), ?) diff --git a/test/files/run/t6440.scala b/test/files/run/t6440.scala new file mode 100644 index 0000000000..2b690f31e1 --- /dev/null +++ b/test/files/run/t6440.scala @@ -0,0 +1,7 @@ +object Test { + + def main(args: Array[String]): Unit = { + println(Stream.continually(()).filterNot(_ => false).take(2)) + } + +} -- cgit v1.2.3