Skip to content

Commit 50caa2c

Browse files
committed
Make WithFilter capture checked
1 parent a5fa6e9 commit 50caa2c

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

tests/pos-special/stdlib/collection/Iterable.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ object IterableOps {
905905
def map[B](f: A => B): CC[B]^{this, f} =
906906
self.iterableFactory.from(new View.Map(filtered, f))
907907

908-
def flatMap[B](f: A => IterableOnce[B]): CC[B]^{this, f} =
908+
def flatMap[B](f: A => IterableOnce[B]^): CC[B]^{this, f} =
909909
self.iterableFactory.from(new View.FlatMap(filtered, f))
910910

911911
def foreach[U](f: A => U): Unit = filtered.foreach(f)

tests/pos-special/stdlib/collection/Map.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,13 +378,13 @@ object MapOps {
378378
p: ((K, V)) => Boolean
379379
) extends IterableOps.WithFilter[(K, V), IterableCC](self, p) with Serializable {
380380

381-
def map[K2, V2](f: ((K, V)) => (K2, V2)): CC[K2, V2] =
381+
def map[K2, V2](f: ((K, V)) => (K2, V2)): CC[K2, V2]^{this, f} =
382382
self.mapFactory.from(new View.Map(filtered, f))
383383

384-
def flatMap[K2, V2](f: ((K, V)) => IterableOnce[(K2, V2)]^): CC[K2, V2] =
384+
def flatMap[K2, V2](f: ((K, V)) => IterableOnce[(K2, V2)]^): CC[K2, V2]^{this, f} =
385385
self.mapFactory.from(new View.FlatMap(filtered, f))
386386

387-
override def withFilter(q: ((K, V)) => Boolean): WithFilter[K, V, IterableCC, CC]^{p, q} =
387+
override def withFilter(q: ((K, V)) => Boolean): WithFilter[K, V, IterableCC, CC]^{this, q} =
388388
new WithFilter[K, V, IterableCC, CC](self, (kv: (K, V)) => p(kv) && q(kv))
389389

390390
}

tests/pos-special/stdlib/collection/WithFilter.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212

1313
package scala.collection
14+
import language.experimental.captureChecking
1415

1516
/** A template trait that contains just the `map`, `flatMap`, `foreach` and `withFilter` methods
1617
* of trait `Iterable`.
@@ -22,6 +23,7 @@ package scala.collection
2223
*/
2324
@SerialVersionUID(3L)
2425
abstract class WithFilter[+A, +CC[_]] extends Serializable {
26+
this: WithFilter[A, CC]^ =>
2527

2628
/** Builds a new collection by applying a function to all elements of the
2729
* `filtered` outer $coll.
@@ -32,7 +34,7 @@ abstract class WithFilter[+A, +CC[_]] extends Serializable {
3234
* the given function `f` to each element of the filtered outer $coll
3335
* and collecting the results.
3436
*/
35-
def map[B](f: A => B): CC[B]
37+
def map[B](f: A => B): CC[B]^{this, f}
3638

3739
/** Builds a new collection by applying a function to all elements of the
3840
* `filtered` outer $coll containing this `WithFilter` instance that satisfy
@@ -44,7 +46,7 @@ abstract class WithFilter[+A, +CC[_]] extends Serializable {
4446
* of the filtered outer $coll and
4547
* concatenating the results.
4648
*/
47-
def flatMap[B](f: A => IterableOnce[B]): CC[B]
49+
def flatMap[B](f: A => IterableOnce[B]^): CC[B]^{this, f}
4850

4951
/** Applies a function `f` to all elements of the `filtered` outer $coll.
5052
*
@@ -65,6 +67,6 @@ abstract class WithFilter[+A, +CC[_]] extends Serializable {
6567
* All these operations apply to those elements of this $coll which
6668
* also satisfy both `p` and `q` predicates.
6769
*/
68-
def withFilter(q: A => Boolean): WithFilter[A, CC]
70+
def withFilter(q: A => Boolean): WithFilter[A, CC]^{this, q}
6971

7072
}

0 commit comments

Comments
 (0)