Skip to content

Commit 5ba4cf7

Browse files
committed
Fixes to capture annotations in stdlib
These problems were discovered once we started recording uses of this references. The recording is not yet part of this commit because it requires downstream bugfixes in the compiler.
1 parent fbbae09 commit 5ba4cf7

File tree

8 files changed

+17
-16
lines changed

8 files changed

+17
-16
lines changed

library/src/scala/collection/Iterator.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ trait Iterator[+A] extends IterableOnce[A] with IterableOnceOps[A, Iterator, Ite
418418

419419
@deprecated("Call scanRight on an Iterable instead.", "2.13.0")
420420
def scanRight[B](z: B)(op: (A, B) => B): Iterator[B]^{this, op} = ArrayBuffer.from(this).scanRight(z)(op).iterator
421-
421+
422422
/** Finds index of the first element satisfying some predicate after or at some start index.
423423
*
424424
* $mayNotTerminateInf
@@ -494,9 +494,9 @@ trait Iterator[+A] extends IterableOnce[A] with IterableOnceOps[A, Iterator, Ite
494494
while (p(hd) == isFlipped) {
495495
if (!self.hasNext) return false
496496
hd = self.next()
497-
}
497+
}
498498
hdDefined = true
499-
true
499+
true
500500
}
501501

502502
def next() =
@@ -874,7 +874,7 @@ trait Iterator[+A] extends IterableOnce[A] with IterableOnceOps[A, Iterator, Ite
874874
*/
875875
def duplicate: (Iterator[A]^{this}, Iterator[A]^{this}) = {
876876
val gap = new scala.collection.mutable.Queue[A]
877-
var ahead: Iterator[A] = null
877+
var ahead: Iterator[A]^ = null
878878
class Partner extends AbstractIterator[A] {
879879
override def knownSize: Int = self.synchronized {
880880
val thisSize = self.knownSize
@@ -890,7 +890,7 @@ trait Iterator[+A] extends IterableOnce[A] with IterableOnceOps[A, Iterator, Ite
890890
if (gap.isEmpty) ahead = this
891891
if (this eq ahead) {
892892
val e = self.next()
893-
gap enqueue e
893+
gap.enqueue(e)
894894
e
895895
} else gap.dequeue()
896896
}
@@ -918,7 +918,7 @@ trait Iterator[+A] extends IterableOnce[A] with IterableOnceOps[A, Iterator, Ite
918918
*/
919919
def patch[B >: A](from: Int, patchElems: Iterator[B]^, replaced: Int): Iterator[B]^{this, patchElems} =
920920
new AbstractIterator[B] {
921-
private[this] var origElems = self
921+
private[this] var origElems: Iterator[B]^ = self
922922
// > 0 => that many more elems from `origElems` before switching to `patchElems`
923923
// 0 => need to drop elems from `origElems` and start using `patchElems`
924924
// -1 => have dropped elems from `origElems`, will be using `patchElems` until it's empty

library/src/scala/collection/LazyZipOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ final class LazyZip4[+El1, +El2, +El3, +El4, C1] private[collection](src: C1,
389389
}
390390

391391
private def toIterable: View[(El1, El2, El3, El4)]^{this} = new AbstractView[(El1, El2, El3, El4)] {
392-
def iterator: AbstractIterator[(El1, El2, El3, El4)] = new AbstractIterator[(El1, El2, El3, El4)] {
392+
def iterator: AbstractIterator[(El1, El2, El3, El4)]^{this} = new AbstractIterator[(El1, El2, El3, El4)] {
393393
private[this] val elems1 = coll1.iterator
394394
private[this] val elems2 = coll2.iterator
395395
private[this] val elems3 = coll3.iterator

library/src/scala/collection/SeqView.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,10 @@ object SeqView {
202202
override def knownSize: Int = len
203203
override def isEmpty: Boolean = len == 0
204204
override def to[C1](factory: Factory[A, C1]): C1 = _sorted.to(factory)
205-
override def reverse: SeqView[A] = new ReverseSorted
205+
override def reverse: SeqView[A]^{this} = new ReverseSorted
206206
// we know `_sorted` is either tiny or has efficient random access,
207207
// so this is acceptable for `reversed`
208-
override protected def reversed: Iterable[A] = new ReverseSorted
208+
override protected def reversed: Iterable[A]^{this} = new ReverseSorted
209209

210210
override def sorted[B1 >: A](implicit ord1: Ordering[B1]): SeqView[A]^{this} =
211211
if (ord1 == this.ord) this

library/src/scala/collection/Stepper.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ trait IntStepper extends Stepper[Int] {
260260

261261
def spliterator[B >: Int]: Spliterator.OfInt^{this} = new IntStepper.IntStepperSpliterator(this)
262262

263-
def javaIterator[B >: Int]: PrimitiveIterator.OfInt = new PrimitiveIterator.OfInt {
263+
def javaIterator[B >: Int]: PrimitiveIterator.OfInt^{this} = new PrimitiveIterator.OfInt {
264264
def hasNext: Boolean = hasStep
265265
def nextInt(): Int = nextStep()
266266
}
@@ -298,7 +298,7 @@ trait DoubleStepper extends Stepper[Double] {
298298

299299
def spliterator[B >: Double]: Spliterator.OfDouble^{this} = new DoubleStepper.DoubleStepperSpliterator(this)
300300

301-
def javaIterator[B >: Double]: PrimitiveIterator.OfDouble = new PrimitiveIterator.OfDouble {
301+
def javaIterator[B >: Double]: PrimitiveIterator.OfDouble^{this} = new PrimitiveIterator.OfDouble {
302302
def hasNext: Boolean = hasStep
303303
def nextDouble(): Double = nextStep()
304304
}
@@ -337,7 +337,7 @@ trait LongStepper extends Stepper[Long] {
337337

338338
def spliterator[B >: Long]: Spliterator.OfLong^{this} = new LongStepper.LongStepperSpliterator(this)
339339

340-
def javaIterator[B >: Long]: PrimitiveIterator.OfLong = new PrimitiveIterator.OfLong {
340+
def javaIterator[B >: Long]: PrimitiveIterator.OfLong^{this} = new PrimitiveIterator.OfLong {
341341
def hasNext: Boolean = hasStep
342342
def nextLong(): Long = nextStep()
343343
}

library/src/scala/collection/View.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ object View extends IterableFactory[View] {
172172

173173
@SerialVersionUID(3L)
174174
class LeftPartitionMapped[A, A1, A2](underlying: SomeIterableOps[A]^, f: A => Either[A1, A2]) extends AbstractView[A1] {
175-
def iterator: AbstractIterator[A1] = new AbstractIterator[A1] {
175+
def iterator: AbstractIterator[A1]^{this} = new AbstractIterator[A1] {
176176
private[this] val self = underlying.iterator
177177
private[this] var hd: A1 = _
178178
private[this] var hdDefined: Boolean = false
@@ -197,7 +197,7 @@ object View extends IterableFactory[View] {
197197

198198
@SerialVersionUID(3L)
199199
class RightPartitionMapped[A, A1, A2](underlying: SomeIterableOps[A]^, f: A => Either[A1, A2]) extends AbstractView[A2] {
200-
def iterator: AbstractIterator[A2] = new AbstractIterator[A2] {
200+
def iterator: AbstractIterator[A2]^{this} = new AbstractIterator[A2] {
201201
private[this] val self = underlying.iterator
202202
private[this] var hd: A2 = _
203203
private[this] var hdDefined: Boolean = false

library/src/scala/collection/convert/StreamExtensions.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import scala.jdk._
3030
* [[scala.jdk.javaapi.StreamConverters]].
3131
*/
3232
trait StreamExtensions {
33+
this: StreamExtensions =>
3334
// collections
3435

3536
implicit class IterableHasSeqStream[A](cc: IterableOnce[A]) {

library/src/scala/collection/mutable/HashTable.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private[collection] trait HashTable[A, B, Entry >: Null <: HashEntry[A, Entry]]
211211

212212
/** An iterator returning all entries.
213213
*/
214-
def entriesIterator: Iterator[Entry] = new AbstractIterator[Entry] {
214+
def entriesIterator: Iterator[Entry]^{this} = new AbstractIterator[Entry] {
215215
val iterTable = table
216216
var idx = lastPopulatedIndex
217217
var es = iterTable(idx)

tests/run-custom-args/captures/colltest5/CollectionStrawManCC5_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ object CollectionStrawMan5 {
423423
def start: Int
424424
def end: Int
425425
def apply(i: Int): A
426-
def iterator: Iterator[A] = new Iterator[A] {
426+
def iterator: Iterator[A]^{this} = new Iterator[A] {
427427
private var current = start
428428
def hasNext = current < end
429429
def next(): A = {

0 commit comments

Comments
 (0)