Skip to content

Commit 2819fa5

Browse files
committed
Address comments
1 parent d0a0974 commit 2819fa5

File tree

7 files changed

+14
-12
lines changed

7 files changed

+14
-12
lines changed

library/src/scala/IArray.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,11 @@ object IArray:
346346
mapNull(arr, ArraySeq.unsafeWrapArray(arr))
347347

348348
/** Conversion from IArray to immutable.ArraySeq */
349-
import scala.language.unsafeNulls // TODO!!! only for stdliib migration!
349+
import scala.language.unsafeNulls // TODO!!! only for stdlib migration!
350350
implicit def wrapRefArray[T <: AnyRef | Null](arr: IArray[T]): ArraySeq.ofRef[T] =
351351
// Since the JVM thinks arrays are covariant, one 0-length Array[AnyRef | Null]
352352
// is as good as another for all T <: AnyRef | Null. Instead of creating 100,000,000
353353
// unique ones by way of this implicit, let's share one.
354-
// import scala.language.unsafeNulls
355354
mapNull(arr,
356355
if (arr.length == 0) ArraySeq.empty[AnyRef | Null].asInstanceOf[ArraySeq.ofRef[T]]
357356
else ArraySeq.ofRef[AnyRef](arr.asInstanceOf[Array[AnyRef]]).asInstanceOf[ArraySeq.ofRef[T]]

library/src/scala/Predef.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ object Predef extends LowPriorityImplicits {
594594
!(x eq y)
595595

596596
extension (opt: Option.type)
597+
@experimental
597598
inline def fromNullable[T](t: T | Null): Option[T] = Option(t).asInstanceOf[Option[T]]
598599

599600
// For backward compatibility with code compiled without -Yexplicit-nulls.

library/src/scala/collection/mutable/AnyRefMap.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class AnyRefMap[K <: AnyRef, V] private[collection] (defaultEntry: K -> V, initi
202202
*/
203203
def getOrNull(key: K): V | Null = {
204204
val i = seekEntry(hashOf(key), key)
205-
if (i < 0) null else _values(i).asInstanceOf[V | Null]
205+
if (i < 0) null else _values(i).asInstanceOf[V]
206206
}
207207

208208
/** Retrieves the value associated with a key.

library/src/scala/collection/mutable/ListBuffer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ class ListBuffer[A]
321321
* @param f the mapping function
322322
* @return this $coll
323323
*/
324-
def flatMapInPlace(f: A => IterableOnce[A]): this.type = {
324+
def flatMapInPlace(f: A => IterableOnce[A]^): this.type = {
325325
mutationCount += 1
326326
var src = first
327327
var dst: List[A] | Null = null

library/src/scala/collection/mutable/LongMap.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ final class LongMap[V] private[collection] (defaultEntry: Long -> V, initialBuff
470470

471471
@deprecated("Use ++ with an explicit collection argument instead of + with varargs", "2.13.0")
472472
override def + [V1 >: V](elem1: (Long, V1), elem2: (Long, V1), elems: (Long, V1)*): LongMap[V1]^{} = {
473+
// TODO: An empty capture annotation is needed in the result type to satisfy the overriding checker.
473474
val m = this + elem1 + elem2
474475
if(elems.isEmpty) m else m.concat(elems)
475476
}

library/src/scala/collection/mutable/RedBlackTree.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ private[collection] object RedBlackTree {
146146
private[this] def minNodeAfter[A, B](node: Node[A, B] | Null, key: A)(implicit ord: Ordering[A]): Node[A, B] | Null = {
147147
if (node eq null) null
148148
else {
149-
var y: Node[A, B] | Null = null
149+
// We know x is not null initially, so y will only be null before the first iteration of the loop.
150+
var y: Node[A, B] = null.asInstanceOf[Node[A, B]]
150151
var x: Node[A, B] | Null = node
151152
var cmp = 1
152153
while ((x ne null) && cmp != 0) {
@@ -176,7 +177,8 @@ private[collection] object RedBlackTree {
176177
private[this] def maxNodeBefore[A, B](node: Node[A, B] | Null, key: A)(implicit ord: Ordering[A]): Node[A, B] | Null = {
177178
if (node eq null) null
178179
else {
179-
var y: Node[A, B] | Null = null
180+
// We know x is not null initially, so y will only be null before the first iteration of the loop.
181+
var y: Node[A, B] = null.asInstanceOf[Node[A, B]]
180182
var x: Node[A, B] | Null = node
181183
var cmp = 1
182184
while ((x ne null) && cmp != 0) {
@@ -364,9 +366,8 @@ private[collection] object RedBlackTree {
364366
* Returns the node that follows `node` in an in-order tree traversal. If `node` has the maximum key (and is,
365367
* therefore, the last node), this method returns `null`.
366368
*/
367-
private[this] def successor[A, B](node: Node[A, B] | Null): Node[A, B] | Null = {
368-
if (node eq null) null
369-
else if (node.right ne null) minNodeNonNull(node.right)
369+
private[this] def successor[A, B](node: Node[A, B]): Node[A, B] | Null = {
370+
if (node.right ne null) minNodeNonNull(node.right)
370371
else {
371372
var x = node
372373
var y = x.parent
@@ -382,9 +383,8 @@ private[collection] object RedBlackTree {
382383
* Returns the node that precedes `node` in an in-order tree traversal. If `node` has the minimum key (and is,
383384
* therefore, the first node), this method returns `null`.
384385
*/
385-
private[this] def predecessor[A, B](node: Node[A, B] | Null): Node[A, B] | Null = {
386-
if (node eq null) null
387-
else if (node.left ne null) maxNodeNonNull(node.left)
386+
private[this] def predecessor[A, B](node: Node[A, B]): Node[A, B] | Null = {
387+
if (node.left ne null) maxNodeNonNull(node.left)
388388
else {
389389
var x = node
390390
var y = x.parent

library/src/scala/runtime/stdLibPatches/Predef.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ object Predef:
6767
!(x eq y)
6868

6969
extension (opt: Option.type)
70+
@experimental
7071
inline def fromNullable[T](t: T | Null): Option[T] = Option(t).asInstanceOf[Option[T]]
7172

7273
/** A type supporting Self-based type classes.

0 commit comments

Comments
 (0)