Skip to content

Commit 5d0e2f3

Browse files
committed
Capture check the standard library under the new scheme
1 parent 8b33e02 commit 5d0e2f3

File tree

6 files changed

+20
-19
lines changed

6 files changed

+20
-19
lines changed

scala2-library-cc/src/scala/collection/Iterable.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -684,9 +684,9 @@ trait IterableOps[+A, +CC[_], +C] extends Any with IterableOnce[A] with Iterable
684684

685685
def map[B](f: A => B): CC[B]^{this, f} = iterableFactory.from(new View.Map(this, f))
686686

687-
def flatMap[B](f: A => IterableOnce[B]^): CC[B]^{this, f} = iterableFactory.from(new View.FlatMap(this, f))
687+
def flatMap[B](f: A => IterableOnce[B]^): CC[B]^{this, f*} = iterableFactory.from(new View.FlatMap(this, f))
688688

689-
def flatten[B](implicit asIterable: A -> IterableOnce[B]): CC[B]^{this} = flatMap(asIterable)
689+
def flatten[B](implicit asIterable: A -> IterableOnce[B]): CC[B]^{this, asIterable*} = flatMap(asIterable)
690690

691691
def collect[B](pf: PartialFunction[A, B]^): CC[B]^{this, pf} =
692692
iterableFactory.from(new View.Collect(this, pf))
@@ -911,7 +911,7 @@ object IterableOps {
911911
def map[B](f: A => B): CC[B]^{this, f} =
912912
self.iterableFactory.from(new View.Map(filtered, f))
913913

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

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

scala2-library-cc/src/scala/collection/IterableOnce.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ final class IterableOnceExtensionMethods[A](private val it: IterableOnce[A]) ext
246246
}
247247

248248
@deprecated("Use .iterator.flatMap instead or consider requiring an Iterable", "2.13.0")
249-
def flatMap[B](f: A => IterableOnce[B]^): IterableOnce[B]^{f} = it match {
249+
def flatMap[B](f: A => IterableOnce[B]^): IterableOnce[B]^{f*} = it match {
250250
case it: Iterable[A] => it.flatMap(f)
251251
case _ => it.iterator.flatMap(f)
252252
}
@@ -439,7 +439,7 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A]^ =>
439439
* @return a new $coll resulting from applying the given collection-valued function
440440
* `f` to each element of this $coll and concatenating the results.
441441
*/
442-
def flatMap[B](f: A => IterableOnce[B]^): CC[B]^{this, f}
442+
def flatMap[B](f: A => IterableOnce[B]^): CC[B]^{this, f*}
443443

444444
/** Converts this $coll of iterable collections into
445445
* a $coll formed by the elements of these iterable

scala2-library-cc/src/scala/collection/Iterator.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,8 @@ trait Iterator[+A] extends IterableOnce[A] with IterableOnceOps[A, Iterator, Ite
588588
def next() = f(self.next())
589589
}
590590

591-
def flatMap[B](f: A => IterableOnce[B]^): Iterator[B]^{this, f} = new AbstractIterator[B] {
592-
private[this] var cur: Iterator[B]^{f} = Iterator.empty
591+
def flatMap[B](f: A => IterableOnce[B]^): Iterator[B]^{this, f*} = new AbstractIterator[B] {
592+
private[this] var cur: Iterator[B]^{f*} = Iterator.empty
593593
/** Trillium logic boolean: -1 = unknown, 0 = false, 1 = true */
594594
private[this] var _hasNext: Int = -1
595595

@@ -623,7 +623,7 @@ trait Iterator[+A] extends IterableOnce[A] with IterableOnceOps[A, Iterator, Ite
623623
}
624624
}
625625

626-
def flatten[B](implicit ev: A -> IterableOnce[B]): Iterator[B]^{this} =
626+
def flatten[B](implicit ev: A -> IterableOnce[B]): Iterator[B]^{this, ev*} =
627627
flatMap[B](ev)
628628

629629
def concat[B >: A](xs: => IterableOnce[B]^): Iterator[B]^{this, xs} = new Iterator.ConcatIterator[B](self).concat(xs)

scala2-library-cc/src/scala/collection/View.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ object View extends IterableFactory[View] {
5757
*
5858
* @tparam A View element type
5959
*/
60-
def fromIteratorProvider[A](it: () => Iterator[A]^): View[A]^{it} = new AbstractView[A] {
61-
def iterator: Iterator[A]^{it} = it()
60+
def fromIteratorProvider[A](it: () => Iterator[A]^): View[A]^{it*} = new AbstractView[A] { // TODO: this seems clearly unsound: not only `it*` but also `it` is used
61+
// why it capture-checks?
62+
def iterator: Iterator[A]^{it*} = it()
6263
}
6364

6465
/**
@@ -310,7 +311,7 @@ object View extends IterableFactory[View] {
310311
/** A view that flatmaps elements of the underlying collection. */
311312
@SerialVersionUID(3L)
312313
class FlatMap[A, B](underlying: SomeIterableOps[A]^, f: A => IterableOnce[B]^) extends AbstractView[B] {
313-
def iterator: Iterator[B]^{underlying, f} = underlying.iterator.flatMap(f)
314+
def iterator: Iterator[B]^{underlying, f*} = underlying.iterator.flatMap(f)
314315
override def knownSize: Int = if (underlying.knownSize == 0) 0 else super.knownSize
315316
override def isEmpty: Boolean = iterator.isEmpty
316317
}

scala2-library-cc/src/scala/collection/WithFilter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ abstract class WithFilter[+A, +CC[_]] extends Serializable {
4545
* of the filtered outer $coll and
4646
* concatenating the results.
4747
*/
48-
def flatMap[B](f: A => IterableOnce[B]^): CC[B]^{this, f}
48+
def flatMap[B](f: A => IterableOnce[B]^): CC[B]^{this, f*}
4949

5050
/** Applies a function `f` to all elements of the `filtered` outer $coll.
5151
*

scala2-library-cc/src/scala/collection/immutable/LazyListIterable.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -592,15 +592,15 @@ final class LazyListIterable[+A] private(@untrackedCaptures lazyState: () => Laz
592592
*/
593593
// optimisations are not for speed, but for functionality
594594
// see tickets #153, #498, #2147, and corresponding tests in run/ (as well as run/stream_flatmap_odds.scala)
595-
override def flatMap[B](f: A => IterableOnce[B]^): LazyListIterable[B]^{this, f} =
595+
override def flatMap[B](f: A => IterableOnce[B]^): LazyListIterable[B]^{this, f*} =
596596
if (knownIsEmpty) LazyListIterable.empty
597597
else LazyListIterable.flatMapImpl(this, f)
598598

599599
/** @inheritdoc
600600
*
601601
* $preservesLaziness
602602
*/
603-
override def flatten[B](implicit asIterable: A -> IterableOnce[B]): LazyListIterable[B]^{this} = flatMap(asIterable)
603+
override def flatten[B](implicit asIterable: A -> IterableOnce[B]): LazyListIterable[B]^{this, asIterable*} = flatMap(asIterable)
604604

605605
/** @inheritdoc
606606
*
@@ -1061,11 +1061,11 @@ object LazyListIterable extends IterableFactory[LazyListIterable] {
10611061
}
10621062
}
10631063

1064-
private def flatMapImpl[A, B](ll: LazyListIterable[A]^, f: A => IterableOnce[B]^): LazyListIterable[B]^{ll, f} = {
1064+
private def flatMapImpl[A, B](ll: LazyListIterable[A]^, f: A => IterableOnce[B]^): LazyListIterable[B]^{ll, f*} = {
10651065
// DO NOT REFERENCE `ll` ANYWHERE ELSE, OR IT WILL LEAK THE HEAD
10661066
var restRef: LazyListIterable[A]^{ll} = ll // restRef is captured by closure arg to newLL, so A is not recognized as parametric
10671067
newLL {
1068-
var it: Iterator[B]^{ll, f} = null
1068+
var it: Iterator[B]^{ll, f*} = null
10691069
var itHasNext = false
10701070
var rest = restRef // var rest = restRef.elem
10711071
while (!itHasNext && !rest.isEmpty) {
@@ -1185,7 +1185,7 @@ object LazyListIterable extends IterableFactory[LazyListIterable] {
11851185
/** Creates a State from an Iterator, with another State appended after the Iterator
11861186
* is empty.
11871187
*/
1188-
private def stateFromIteratorConcatSuffix[A](it: Iterator[A]^)(suffix: => State[A]^): State[A]^{it, suffix} =
1188+
private def stateFromIteratorConcatSuffix[A](it: Iterator[A]^)(suffix: => State[A]^): State[A]^{it, suffix*} =
11891189
if (it.hasNext) sCons(it.next(), newLL(stateFromIteratorConcatSuffix(it)(suffix)))
11901190
else suffix
11911191

@@ -1307,7 +1307,7 @@ object LazyListIterable extends IterableFactory[LazyListIterable] {
13071307
extends collection.WithFilter[A, LazyListIterable] {
13081308
private[this] val filtered = lazyList.filter(p)
13091309
def map[B](f: A => B): LazyListIterable[B]^{this, f} = filtered.map(f)
1310-
def flatMap[B](f: A => IterableOnce[B]^): LazyListIterable[B]^{this, f} = filtered.flatMap(f)
1310+
def flatMap[B](f: A => IterableOnce[B]^): LazyListIterable[B]^{this, f*} = filtered.flatMap(f)
13111311
def foreach[U](f: A => U): Unit = filtered.foreach(f)
13121312
def withFilter(q: A => Boolean): collection.WithFilter[A, LazyListIterable]^{this, q} = new WithFilter(filtered, q)
13131313
}
@@ -1353,7 +1353,7 @@ object LazyListIterable extends IterableFactory[LazyListIterable] {
13531353
final class DeferredState[A] {
13541354
private[this] var _state: (() => State[A]^) @uncheckedCaptures = _
13551355

1356-
def eval(): State[A]^ = {
1356+
def eval(): State[A]^{this} = {
13571357
val state = _state
13581358
if (state == null) throw new IllegalStateException("uninitialized")
13591359
state()

0 commit comments

Comments
 (0)