@@ -54,7 +54,7 @@ object ScalaRunTime {
54
54
classTag[T ].runtimeClass.asInstanceOf [jClass[T ]]
55
55
56
56
/** Retrieve generic array element */
57
- def array_apply (xs : AnyRef | Null , idx : Int ): Any = {
57
+ def array_apply (xs : AnyRef , idx : Int ): Any = {
58
58
(xs : @ unchecked) match {
59
59
case x : Array [AnyRef ] => x(idx).asInstanceOf [Any ]
60
60
case x : Array [Int ] => x(idx).asInstanceOf [Any ]
@@ -70,7 +70,7 @@ object ScalaRunTime {
70
70
}
71
71
72
72
/** update generic array element */
73
- def array_update (xs : AnyRef | Null , idx : Int , value : Any ): Unit = {
73
+ def array_update (xs : AnyRef , idx : Int , value : Any ): Unit = {
74
74
(xs : @ unchecked) match {
75
75
case x : Array [AnyRef ] => x(idx) = value.asInstanceOf [AnyRef ]
76
76
case x : Array [Int ] => x(idx) = value.asInstanceOf [Int ]
@@ -86,11 +86,11 @@ object ScalaRunTime {
86
86
}
87
87
88
88
/** Get generic array length */
89
- @ inline def array_length (xs : AnyRef | Null ): Int = java.lang.reflect.Array .getLength(xs)
89
+ @ inline def array_length (xs : AnyRef ): Int = java.lang.reflect.Array .getLength(xs)
90
90
91
91
// TODO: bytecode Object.clone() will in fact work here and avoids
92
92
// the type switch. See Array_clone comment in BCodeBodyBuilder.
93
- def array_clone (xs : AnyRef | Null ): AnyRef = (xs : @ unchecked) match {
93
+ def array_clone (xs : AnyRef ): AnyRef = (xs : @ unchecked) match {
94
94
case x : Array [AnyRef ] => x.clone()
95
95
case x : Array [Int ] => x.clone()
96
96
case x : Array [Double ] => x.clone()
@@ -107,7 +107,7 @@ object ScalaRunTime {
107
107
* Needed to deal with vararg arguments of primitive types that are passed
108
108
* to a generic Java vararg parameter T ...
109
109
*/
110
- def toObjectArray (src : AnyRef | Null ): Array [Object ] = {
110
+ def toObjectArray (src : AnyRef ): Array [Object ] = {
111
111
def copy [@ specialized T <: AnyVal ](src : Array [T ]): Array [Object ] = {
112
112
val length = src.length
113
113
if (length == 0 ) Array .emptyObjectArray
@@ -281,6 +281,14 @@ object ScalaRunTime {
281
281
case s => s + " \n "
282
282
}
283
283
284
+ // For backward compatibility with code compiled without -Yexplicit-nulls.
285
+ // If `a` is null, return null; otherwise, return `f`.
286
+ private [scala] inline def mapNull [A , B ](a : A , inline f : B ): B =
287
+ if ((a : A | Null ) == null ) null .asInstanceOf [B ] else f
288
+
289
+ // Use `null` in places where we want to make sure the reference is cleared.
290
+ private [scala] inline def nullForGC [T ]: T = null .asInstanceOf [T ]
291
+
284
292
// Convert arrays to immutable.ArraySeq for use with Scala varargs.
285
293
// By construction, calls to these methods always receive a fresh (and non-null), non-empty array.
286
294
// In cases where an empty array would appear, the compiler uses a direct reference to Nil instead.
0 commit comments