Skip to content

Commit a4568ac

Browse files
committed
Adjust some type parameters
1 parent 2d178a7 commit a4568ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+433
-422
lines changed

library/src/scala/Array.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ object Array {
586586
def get: UnapplySeqWrapper[T] = this
587587
def lengthCompare(len: Int): Int = a.lengthCompare(len)
588588
def apply(i: Int): T = a(i)
589-
def drop(n: Int): scala.Seq[T] = ArraySeq.unsafeWrapArray(a.drop(n)) // clones the array, also if n == 0
589+
def drop(n: Int): scala.Seq[T] = ArraySeq.unsafeWrapArray(a.drop(n)).nn // clones the array, also if n == 0
590590
def toSeq: scala.Seq[T] = a.toSeq // clones the array
591591
}
592592
}

library/src/scala/IArray.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,19 +332,19 @@ object IArray:
332332

333333
// For backwards compatibility with code compiled without -Yexplicit-nulls
334334
private inline def mapNull[A, B](a: A, inline f: B): B =
335-
if((a: A|Null) == null) null.asInstanceOf[B] else f
335+
if((a: A | Null) == null) null.asInstanceOf[B] else f
336336

337337
/** Conversion from IArray to immutable.ArraySeq */
338338
implicit def genericWrapArray[T](arr: IArray[T]): ArraySeq[T] =
339-
mapNull(arr, ArraySeq.unsafeWrapArray(arr))
339+
mapNull(arr, ArraySeq.unsafeWrapArray(arr)).asInstanceOf[ArraySeq[T]]
340340

341341
/** Conversion from IArray to immutable.ArraySeq */
342-
implicit def wrapRefArray[T <: AnyRef](arr: IArray[T]): ArraySeq.ofRef[T] =
343-
// Since the JVM thinks arrays are covariant, one 0-length Array[AnyRef]
344-
// is as good as another for all T <: AnyRef. Instead of creating 100,000,000
342+
implicit def wrapRefArray[T <: AnyRef | Null](arr: IArray[T]): ArraySeq.ofRef[T] =
343+
// Since the JVM thinks arrays are covariant, one 0-length Array[AnyRef | Null]
344+
// is as good as another for all T <: AnyRef | Null. Instead of creating 100,000,000
345345
// unique ones by way of this implicit, let's share one.
346346
mapNull(arr,
347-
if (arr.length == 0) ArraySeq.empty[AnyRef].asInstanceOf[ArraySeq.ofRef[T]]
347+
if (arr.length == 0) ArraySeq.empty[AnyRef | Null].asInstanceOf[ArraySeq.ofRef[T]]
348348
else ArraySeq.ofRef(arr.asInstanceOf[Array[T]])
349349
)
350350

library/src/scala/Predef.scala

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -657,47 +657,49 @@ private[scala] abstract class LowPriorityImplicits extends LowPriorityImplicits2
657657
@inline implicit def doubleWrapper(x: Double): runtime.RichDouble = new runtime.RichDouble(x)
658658
@inline implicit def booleanWrapper(x: Boolean): runtime.RichBoolean = new runtime.RichBoolean(x)
659659

660+
// For backwards compatibility with code compiled without -Yexplicit-nulls
661+
private inline def mapNull[A, B](a: A, inline f: B): B =
662+
if((a: A | Null) == null) null.asInstanceOf[B] else f
663+
660664
/** @group conversions-array-to-wrapped-array */
661-
implicit def genericWrapArray[T](xs: Array[T] | Null): ArraySeq[T] | Null =
662-
if (xs eq null) null
663-
else ArraySeq.make(xs)
665+
implicit def genericWrapArray[T](xs: Array[T]): ArraySeq[T] =
666+
mapNull(xs, ArraySeq.make(xs))
664667

665668
// Since the JVM thinks arrays are covariant, one 0-length Array[AnyRef]
666669
// is as good as another for all T <: AnyRef. Instead of creating 100,000,000
667670
// unique ones by way of this implicit, let's share one.
668671
/** @group conversions-array-to-wrapped-array */
669-
implicit def wrapRefArray[T <: AnyRef](xs: Array[T] | Null): ArraySeq.ofRef[T] | Null = {
670-
if (xs eq null) null
671-
else if (xs.length == 0) ArraySeq.empty[AnyRef].asInstanceOf[ArraySeq.ofRef[T]]
672-
else new ArraySeq.ofRef[T](xs)
673-
}
672+
implicit def wrapRefArray[T <: AnyRef | Null](xs: Array[T]): ArraySeq.ofRef[T] =
673+
mapNull(xs,
674+
if (xs.length == 0) ArraySeq.empty[AnyRef].asInstanceOf[ArraySeq.ofRef[T]]
675+
else new ArraySeq.ofRef[T](xs))
674676

675677
/** @group conversions-array-to-wrapped-array */
676-
implicit def wrapIntArray(xs: Array[Int] | Null): ArraySeq.ofInt | Null = if (xs ne null) new ArraySeq.ofInt(xs) else null
678+
implicit def wrapIntArray(xs: Array[Int]): ArraySeq.ofInt = mapNull(xs, new ArraySeq.ofInt(xs))
677679
/** @group conversions-array-to-wrapped-array */
678-
implicit def wrapDoubleArray(xs: Array[Double] | Null): ArraySeq.ofDouble | Null = if (xs ne null) new ArraySeq.ofDouble(xs) else null
680+
implicit def wrapDoubleArray(xs: Array[Double]): ArraySeq.ofDouble = mapNull(xs, new ArraySeq.ofDouble(xs))
679681
/** @group conversions-array-to-wrapped-array */
680-
implicit def wrapLongArray(xs: Array[Long] | Null): ArraySeq.ofLong | Null = if (xs ne null) new ArraySeq.ofLong(xs) else null
682+
implicit def wrapLongArray(xs: Array[Long]): ArraySeq.ofLong = mapNull(xs, new ArraySeq.ofLong(xs))
681683
/** @group conversions-array-to-wrapped-array */
682-
implicit def wrapFloatArray(xs: Array[Float] | Null): ArraySeq.ofFloat | Null = if (xs ne null) new ArraySeq.ofFloat(xs) else null
684+
implicit def wrapFloatArray(xs: Array[Float]): ArraySeq.ofFloat = mapNull(xs, new ArraySeq.ofFloat(xs))
683685
/** @group conversions-array-to-wrapped-array */
684-
implicit def wrapCharArray(xs: Array[Char] | Null): ArraySeq.ofChar | Null = if (xs ne null) new ArraySeq.ofChar(xs) else null
686+
implicit def wrapCharArray(xs: Array[Char]): ArraySeq.ofChar = mapNull(xs, new ArraySeq.ofChar(xs))
685687
/** @group conversions-array-to-wrapped-array */
686-
implicit def wrapByteArray(xs: Array[Byte] | Null): ArraySeq.ofByte | Null = if (xs ne null) new ArraySeq.ofByte(xs) else null
688+
implicit def wrapByteArray(xs: Array[Byte]): ArraySeq.ofByte = mapNull(xs, new ArraySeq.ofByte(xs))
687689
/** @group conversions-array-to-wrapped-array */
688-
implicit def wrapShortArray(xs: Array[Short] | Null): ArraySeq.ofShort | Null = if (xs ne null) new ArraySeq.ofShort(xs) else null
690+
implicit def wrapShortArray(xs: Array[Short]): ArraySeq.ofShort = mapNull(xs, new ArraySeq.ofShort(xs))
689691
/** @group conversions-array-to-wrapped-array */
690-
implicit def wrapBooleanArray(xs: Array[Boolean] | Null): ArraySeq.ofBoolean | Null = if (xs ne null) new ArraySeq.ofBoolean(xs) else null
692+
implicit def wrapBooleanArray(xs: Array[Boolean]): ArraySeq.ofBoolean = mapNull(xs, new ArraySeq.ofBoolean(xs))
691693
/** @group conversions-array-to-wrapped-array */
692-
implicit def wrapUnitArray(xs: Array[Unit] | Null): ArraySeq.ofUnit | Null = if (xs ne null) new ArraySeq.ofUnit(xs) else null
694+
implicit def wrapUnitArray(xs: Array[Unit]): ArraySeq.ofUnit = mapNull(xs, new ArraySeq.ofUnit(xs))
693695

694696
/** @group conversions-string */
695-
implicit def wrapString(s: String | Null): WrappedString | Null = if (s ne null) new WrappedString(s) else null
697+
implicit def wrapString(s: String): WrappedString = mapNull(s, new WrappedString(s))
696698
}
697699

698700
private[scala] abstract class LowPriorityImplicits2 {
699701
@deprecated("implicit conversions from Array to immutable.IndexedSeq are implemented by copying; use `toIndexedSeq` explicitly if you want to copy, or use the more efficient non-copying ArraySeq.unsafeWrapArray", since="2.13.0")
700-
implicit def copyArrayToImmutableIndexedSeq[T](xs: Array[T] | Null): IndexedSeq[T] | Null =
701-
if (xs eq null) null
702+
implicit def copyArrayToImmutableIndexedSeq[T](xs: Array[T]): IndexedSeq[T] =
703+
if (xs eq null) null.asInstanceOf[IndexedSeq[T]]
702704
else new ArrayOps(xs).toIndexedSeq
703705
}

library/src/scala/StringContext.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ object StringContext {
293293
// Matched all of pattern to all of name. Success.
294294
Some(collection.immutable.ArraySeq.unsafeWrapArray(
295295
Array.tabulate(patternChunks.length - 1)(n => input.slice(matchStarts(n), matchEnds(n)))
296-
))
296+
).nn)
297297
}
298298

299299
/** An exception that is thrown if a string contains a backslash (`\`) character
@@ -475,3 +475,4 @@ object StringContext {
475475
+") for interpolated string with "+ parts.length +" parts")
476476

477477
}
478+

library/src/scala/Symbol.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ object Symbol extends UniquenessCache[String, Symbol] {
3636

3737
/** This is private so it won't appear in the library API, but
3838
* abstracted to offer some hope of reusability. */
39-
private[scala] abstract class UniquenessCache[K, V >: Null] {
39+
private[scala] abstract class UniquenessCache[K, V] {
4040
import java.lang.ref.WeakReference
4141
import java.util.WeakHashMap
4242
import java.util.concurrent.locks.ReentrantReadWriteLock
@@ -50,7 +50,7 @@ private[scala] abstract class UniquenessCache[K, V >: Null] {
5050
protected def keyFromValue(v: V): Option[K]
5151

5252
def apply(name: K): V = {
53-
def cached(): V = {
53+
def cached(): V | Null = {
5454
rlock.lock
5555
try {
5656
val reference = map get name

library/src/scala/collection/ArrayOps.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ object ArrayOps {
6060
private class ArrayView[A](xs: Array[A]) extends AbstractIndexedSeqView[A] {
6161
def length = xs.length
6262
def apply(n: Int) = xs(n)
63-
override def toString: String = immutable.ArraySeq.unsafeWrapArray(xs).mkString("ArrayView(", ", ", ")")
63+
override def toString: String = immutable.ArraySeq.unsafeWrapArray(xs).nn.mkString("ArrayView(", ", ", ")")
6464
}
6565

6666
/** A lazy filtered array. No filtering is applied until one of `foreach`, `map` or `flatMap` is called. */
@@ -429,7 +429,7 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal {
429429
val s = (shape.shape: @unchecked) match {
430430
case StepperShape.ReferenceShape => (xs: Any) match {
431431
case bs: Array[Boolean] => new BoxedBooleanArrayStepper(bs, 0, xs.length)
432-
case _ => new ObjectArrayStepper[AnyRef](xs.asInstanceOf[Array[AnyRef ]], 0, xs.length)
432+
case _ => new ObjectArrayStepper[AnyRef](xs.asInstanceOf[Array[AnyRef]], 0, xs.length)
433433
}
434434
case StepperShape.IntShape => new IntArrayStepper (xs.asInstanceOf[Array[Int ]], 0, xs.length)
435435
case StepperShape.LongShape => new LongArrayStepper (xs.asInstanceOf[Array[Long ]], 0, xs.length)
@@ -1084,7 +1084,7 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal {
10841084
* @return a decorator `LazyZip2` that allows strict operations to be performed on the lazily evaluated pairs
10851085
* or chained calls to `lazyZip`. Implicit conversion to `Iterable[(A, B)]` is also supported.
10861086
*/
1087-
def lazyZip[B](that: Iterable[B]^): LazyZip2[A, B, Array[A]]^{that} = new LazyZip2(xs, immutable.ArraySeq.unsafeWrapArray(xs), that)
1087+
def lazyZip[B](that: Iterable[B]^): LazyZip2[A, B, Array[A]]^{that} = new LazyZip2(xs, immutable.ArraySeq.unsafeWrapArray(xs).nn, that)
10881088

10891089
/** Returns an array formed from this array and another iterable collection
10901090
* by combining corresponding elements in pairs.
@@ -1438,7 +1438,7 @@ final class ArrayOps[A](private val xs: Array[A]) extends AnyVal {
14381438
@`inline` final def toSeq: immutable.Seq[A] = toIndexedSeq
14391439

14401440
def toIndexedSeq: immutable.IndexedSeq[A] =
1441-
immutable.ArraySeq.unsafeWrapArray(Array.copyOf(xs, xs.length))
1441+
immutable.ArraySeq.unsafeWrapArray(Array.copyOf(xs, xs.length)).nn
14421442

14431443
/** Copy elements of this array to another array.
14441444
* Fills the given array `xs` starting at index 0.

library/src/scala/collection/SeqView.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ object SeqView {
138138
extends SeqView[A] {
139139
outer: Sorted[A, B]^ =>
140140

141-
private var underlying = underlying_
141+
private var underlying: SomeSeqOps[A] | Null = underlying_
142142

143143
// force evaluation immediately by calling `length` so infinite collections
144144
// hang on `sorted`/`sortWith`/`sortBy` rather than on arbitrary method calls
@@ -169,10 +169,10 @@ object SeqView {
169169
val res = {
170170
val len = this.len
171171
if (len == 0) Nil
172-
else if (len == 1) List(underlying.head)
172+
else if (len == 1) List(underlying.nn.head)
173173
else {
174174
val arr = new Array[Any](len) // Array[Any] =:= Array[AnyRef]
175-
@annotation.unused val copied = underlying.copyToArray(arr)
175+
@annotation.unused val copied = underlying.nn.copyToArray(arr)
176176
//assert(copied == len)
177177
java.util.Arrays.sort(arr.asInstanceOf[Array[AnyRef]], ord.asInstanceOf[Ordering[AnyRef]])
178178
// casting the Array[AnyRef] to Array[A] and creating an ArraySeq from it
@@ -183,7 +183,7 @@ object SeqView {
183183
// contains items of another type, we'd get a CCE anyway)
184184
// - the cast doesn't actually do anything in the runtime because the
185185
// type of A is not known and Array[_] is Array[AnyRef]
186-
immutable.ArraySeq.unsafeWrapArray(arr.asInstanceOf[Array[A]])
186+
immutable.ArraySeq.unsafeWrapArray(arr.asInstanceOf[Array[A]]).nn
187187
}
188188
}
189189
evaluated = true
@@ -192,7 +192,7 @@ object SeqView {
192192
}
193193

194194
private[this] def elems: SomeSeqOps[A]^{this} = {
195-
val orig: SomeSeqOps[A]^{this} = underlying
195+
val orig: SomeSeqOps[A]^{this} = underlying.nn
196196
if (evaluated) _sorted else orig
197197
}
198198

library/src/scala/collection/View.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -459,13 +459,13 @@ object View extends IterableFactory[View] {
459459
len = 0
460460
while(underlying.hasNext) {
461461
val n = underlying.next().asInstanceOf[AnyRef]
462-
if(pos >= buf.length) buf.addOne(n)
463-
else buf(pos) = n
462+
if(pos >= buf.nn.length) buf.nn.addOne(n)
463+
else buf.nn(pos) = n
464464
pos += 1
465465
if(pos == maxlen) pos = 0
466466
len += 1
467467
}
468-
underlying = null
468+
underlying = null.asInstanceOf[Iterator[A]^] // allow GC of underlying iterator
469469
if(len > maxlen) len = maxlen
470470
pos = pos - len
471471
if(pos < 0) pos += maxlen
@@ -479,7 +479,7 @@ object View extends IterableFactory[View] {
479479
init()
480480
if(len == 0) Iterator.empty.next()
481481
else {
482-
val x = buf(pos).asInstanceOf[A]
482+
val x = buf.nn(pos).asInstanceOf[A]
483483
pos += 1
484484
if(pos == maxlen) pos = 0
485485
len -= 1
@@ -513,7 +513,7 @@ object View extends IterableFactory[View] {
513513
def init(): Unit = if(buf eq null) {
514514
buf = new ArrayBuffer[AnyRef](maxlen min 256)
515515
while(pos < maxlen && underlying.hasNext) {
516-
buf.addOne(underlying.next().asInstanceOf[AnyRef])
516+
buf.nn.addOne(underlying.next().asInstanceOf[AnyRef])
517517
pos += 1
518518
}
519519
if(!underlying.hasNext) len = 0
@@ -527,9 +527,9 @@ object View extends IterableFactory[View] {
527527
def next(): A = {
528528
if(!hasNext) Iterator.empty.next()
529529
else {
530-
val x = buf(pos).asInstanceOf[A]
530+
val x = buf.nn(pos).asInstanceOf[A]
531531
if(len == -1) {
532-
buf(pos) = underlying.next().asInstanceOf[AnyRef]
532+
buf.nn(pos) = underlying.next().asInstanceOf[AnyRef]
533533
if(!underlying.hasNext) len = 0
534534
} else len -= 1
535535
pos += 1

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ trait StreamExtensions {
303303
if (info.companion == AnyAccumulator) stream.collect(AnyAccumulator.supplier[Int], AnyAccumulator.unboxedIntAdder, AnyAccumulator.merger[Int]).asInstanceOf[C1]
304304
else if (info.companion == IntAccumulator) intAcc.asInstanceOf[C1]
305305
else if (stream.isParallel) intAcc.to(factory)
306-
else factory.fromSpecific(stream.iterator.asInstanceOf[java.util.Iterator[Int]].asScala)
306+
else factory.fromSpecific(stream.iterator.asInstanceOf[java.util.Iterator[Int]].asScala.nn)
307307
}
308308
}
309309

@@ -330,7 +330,7 @@ trait StreamExtensions {
330330
if (info.companion == AnyAccumulator) stream.collect(AnyAccumulator.supplier[Long], AnyAccumulator.unboxedLongAdder, AnyAccumulator.merger[Long]).asInstanceOf[C1]
331331
else if (info.companion == LongAccumulator) longAcc.asInstanceOf[C1]
332332
else if (stream.isParallel) longAcc.to(factory)
333-
else factory.fromSpecific(stream.iterator.asInstanceOf[java.util.Iterator[Long]].asScala)
333+
else factory.fromSpecific(stream.iterator.asInstanceOf[java.util.Iterator[Long]].asScala.nn)
334334
}
335335
}
336336

@@ -357,7 +357,7 @@ trait StreamExtensions {
357357
if (info.companion == AnyAccumulator) stream.collect(AnyAccumulator.supplier[Double], AnyAccumulator.unboxedDoubleAdder, AnyAccumulator.merger[Double]).asInstanceOf[C1]
358358
else if (info.companion == DoubleAccumulator) doubleAcc.asInstanceOf[C1]
359359
else if (stream.isParallel) doubleAcc.to(factory)
360-
else factory.fromSpecific(stream.iterator.asInstanceOf[java.util.Iterator[Double]].asScala)
360+
else factory.fromSpecific(stream.iterator.asInstanceOf[java.util.Iterator[Double]].asScala.nn)
361361
}
362362
}
363363
}

library/src/scala/collection/convert/impl/ArrayStepper.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package impl
1616
import scala.language.`2.13`
1717
import scala.collection._
1818

19-
private[collection] class ObjectArrayStepper[A <: Object](underlying: Array[A], _i0: Int, _iN: Int)
19+
private[collection] class ObjectArrayStepper[A <: Object | Null](underlying: Array[A], _i0: Int, _iN: Int)
2020
extends IndexedStepperBase[AnyStepper[A], ObjectArrayStepper[A]](_i0, _iN)
2121
with AnyStepper[A] {
2222
def nextStep(): A = if (hasStep) { val j = i0; i0 += 1; underlying(j) } else Stepper.throwNSEE()

0 commit comments

Comments
 (0)