@@ -20,6 +20,8 @@ import scala.annotation.nowarn
20
20
import scala .annotation .tailrec
21
21
import scala .collection .Stepper .EfficientSplit
22
22
import scala .collection .generic .DefaultSerializable
23
+ import language .experimental .captureChecking
24
+ import scala .annotation .unchecked .uncheckedCaptures
23
25
24
26
/** An implementation of the `Buffer` class using an array to
25
27
* represent the assembled sequence internally. Append, update and random
@@ -40,7 +42,7 @@ import scala.collection.generic.DefaultSerializable
40
42
* @define willNotTerminateInf
41
43
*/
42
44
@ SerialVersionUID (- 1582447879429021880L )
43
- class ArrayBuffer [A ] private (initialElements : Array [AnyRef ], initialSize : Int )
45
+ class ArrayBuffer [sealed A ] private (initialElements : Array [AnyRef ], initialSize : Int )
44
46
extends AbstractBuffer [A ]
45
47
with IndexedBuffer [A ]
46
48
with IndexedSeqOps [A , ArrayBuffer , ArrayBuffer [A ]]
@@ -151,7 +153,7 @@ class ArrayBuffer[A] private (initialElements: Array[AnyRef], initialSize: Int)
151
153
}
152
154
153
155
// Overridden to use array copying for efficiency where possible.
154
- override def addAll (elems : IterableOnce [A ]): this .type = {
156
+ override def addAll (elems : IterableOnce [A ]^ ): this .type = {
155
157
elems match {
156
158
case elems : ArrayBuffer [_] =>
157
159
val elemsLength = elems.size0
@@ -180,7 +182,7 @@ class ArrayBuffer[A] private (initialElements: Array[AnyRef], initialSize: Int)
180
182
this
181
183
}
182
184
183
- def insertAll (@ deprecatedName(" n" , " 2.13.0" ) index : Int , elems : IterableOnce [A ]): Unit = {
185
+ def insertAll (@ deprecatedName(" n" , " 2.13.0" ) index : Int , elems : IterableOnce [A ]^ ): Unit = {
184
186
checkWithinBounds(index, index)
185
187
elems match {
186
188
case elems : collection.Iterable [A ] =>
@@ -234,7 +236,7 @@ class ArrayBuffer[A] private (initialElements: Array[AnyRef], initialSize: Int)
234
236
235
237
@ deprecated(" Use 'new GrowableBuilder(this).mapResult(f)' instead" , " 2.13.0" )
236
238
@ deprecatedOverriding(" ArrayBuffer[A] no longer extends Builder[A, ArrayBuffer[A]]" , " 2.13.0" )
237
- @ inline def mapResult [NewTo ](f : (ArrayBuffer [A ]) => NewTo ): Builder [A , NewTo ] = new GrowableBuilder [A , ArrayBuffer [A ]](this ).mapResult(f)
239
+ @ inline def mapResult [NewTo ](f : (ArrayBuffer [A ]) => NewTo ): Builder [A , NewTo ]^ {f} = new GrowableBuilder [A , ArrayBuffer [A ]](this ).mapResult(f)
238
240
239
241
@ nowarn(""" cat=deprecation&origin=scala\.collection\.Iterable\.stringPrefix""" )
240
242
override protected [this ] def stringPrefix = " ArrayBuffer"
@@ -291,7 +293,7 @@ object ArrayBuffer extends StrictOptimizedSeqFactory[ArrayBuffer] {
291
293
final val DefaultInitialSize = 16
292
294
private [this ] val emptyArray = new Array [AnyRef ](0 )
293
295
294
- def from [B ](coll : collection.IterableOnce [B ]): ArrayBuffer [B ] = {
296
+ def from [sealed B ](coll : collection.IterableOnce [B ]^ ): ArrayBuffer [B ] = {
295
297
val k = coll.knownSize
296
298
if (k >= 0 ) {
297
299
// Avoid reallocation of buffer if length is known
@@ -303,12 +305,12 @@ object ArrayBuffer extends StrictOptimizedSeqFactory[ArrayBuffer] {
303
305
else new ArrayBuffer [B ] ++= coll
304
306
}
305
307
306
- def newBuilder [A ]: Builder [A , ArrayBuffer [A ]] =
308
+ def newBuilder [sealed A ]: Builder [A , ArrayBuffer [A ]] =
307
309
new GrowableBuilder [A , ArrayBuffer [A ]](empty) {
308
310
override def sizeHint (size : Int ): Unit = elems.ensureSize(size)
309
311
}
310
312
311
- def empty [A ]: ArrayBuffer [A ] = new ArrayBuffer [A ]()
313
+ def empty [sealed A ]: ArrayBuffer [A ] = new ArrayBuffer [A ]()
312
314
313
315
/**
314
316
* @param arrayLen the length of the backing array
@@ -357,22 +359,23 @@ object ArrayBuffer extends StrictOptimizedSeqFactory[ArrayBuffer] {
357
359
}
358
360
359
361
// TODO: use `CheckedIndexedSeqView.Id` once we can change the return type of `ArrayBuffer#view`
360
- final class ArrayBufferView [A ] private [mutable](underlying : ArrayBuffer [A ], mutationCount : () => Int )
361
- extends AbstractIndexedSeqView [A ] {
362
+ final class ArrayBufferView [sealed A ] private [mutable](underlying : ArrayBuffer [A ], mutationCount : () -> Int )
363
+ extends AbstractIndexedSeqView [A ], Pure {
364
+ /* Removed since it poses problems for capture checking
362
365
@deprecated("never intended to be public; call ArrayBuffer#view instead", since = "2.13.7")
363
366
def this(array: Array[AnyRef], length: Int) = {
364
367
// this won't actually track mutation, but it would be a pain to have the implementation
365
368
// check if we have a method to get the current mutation count or not on every method and
366
369
// change what it does based on that. hopefully no one ever calls this.
367
370
this({
368
- val _array = array
371
+ val _array: Array[Object] = array
369
372
val _length = length
370
373
new ArrayBuffer[A](0) {
371
374
this.array = _array
372
375
this.size0 = _length
373
- }
376
+ }: ArrayBuffer[A]
374
377
}, () => 0)
375
- }
378
+ }*/
376
379
377
380
@ deprecated(" never intended to be public" , since = " 2.13.7" )
378
381
def array : Array [AnyRef ] = underlying.toArray[Any ].asInstanceOf [Array [AnyRef ]]
@@ -392,10 +395,10 @@ final class ArrayBufferView[A] private[mutable](underlying: ArrayBuffer[A], muta
392
395
override def takeRight (n : Int ): IndexedSeqView [A ] = new CheckedIndexedSeqView .TakeRight (this , n)(mutationCount)
393
396
override def drop (n : Int ): IndexedSeqView [A ] = new CheckedIndexedSeqView .Drop (this , n)(mutationCount)
394
397
override def dropRight (n : Int ): IndexedSeqView [A ] = new CheckedIndexedSeqView .DropRight (this , n)(mutationCount)
395
- override def map [B ](f : A => B ): IndexedSeqView [B ] = new CheckedIndexedSeqView .Map (this , f)(mutationCount)
398
+ override def map [B ](f : A => B ): IndexedSeqView [B ]^ {f} = new CheckedIndexedSeqView .Map (this , f)(mutationCount)
396
399
override def reverse : IndexedSeqView [A ] = new CheckedIndexedSeqView .Reverse (this )(mutationCount)
397
400
override def slice (from : Int , until : Int ): IndexedSeqView [A ] = new CheckedIndexedSeqView .Slice (this , from, until)(mutationCount)
398
- override def tapEach [U ](f : A => U ): IndexedSeqView [A ] = new CheckedIndexedSeqView .Map (this , { (a : A ) => f(a); a})(mutationCount)
401
+ override def tapEach [U ](f : A => U ): IndexedSeqView [A ]^ {f} = new CheckedIndexedSeqView .Map (this , { (a : A ) => f(a); a})(mutationCount)
399
402
400
403
override def concat [B >: A ](suffix : IndexedSeqView .SomeIndexedSeqOps [B ]): IndexedSeqView [B ] = new CheckedIndexedSeqView .Concat (this , suffix)(mutationCount)
401
404
override def appendedAll [B >: A ](suffix : IndexedSeqView .SomeIndexedSeqOps [B ]): IndexedSeqView [B ] = new CheckedIndexedSeqView .Concat (this , suffix)(mutationCount)
0 commit comments