@@ -328,54 +328,59 @@ object IArray:
328
328
extension [T , U >: T : ClassTag ](x : T )
329
329
def +: (arr : IArray [U ]): IArray [U ] = genericArrayOps(arr).prepended(x)
330
330
331
+ // For backwards compatibility with code compiled without -Yexplicit-nulls
332
+ private inline def mapNull [A , B ](a : A , inline f : B ): B =
333
+ if ((a : A | Null ) == null ) null .asInstanceOf [B ] else f
334
+
331
335
/** Conversion from IArray to immutable.ArraySeq */
332
336
implicit def genericWrapArray [T ](arr : IArray [T ]): ArraySeq [T ] =
333
- if arr eq null then null else ArraySeq .unsafeWrapArray(arr)
337
+ mapNull( arr, ArraySeq .unsafeWrapArray(arr) )
334
338
335
339
/** Conversion from IArray to immutable.ArraySeq */
336
340
implicit def wrapRefArray [T <: AnyRef ](arr : IArray [T ]): ArraySeq .ofRef[T ] =
337
341
// Since the JVM thinks arrays are covariant, one 0-length Array[AnyRef]
338
342
// is as good as another for all T <: AnyRef. Instead of creating 100,000,000
339
343
// unique ones by way of this implicit, let's share one.
340
- if (arr eq null ) null
341
- else if (arr.length == 0 ) ArraySeq .empty[AnyRef ].asInstanceOf [ArraySeq .ofRef[T ]]
342
- else ArraySeq .ofRef(arr.asInstanceOf [Array [T ]])
344
+ mapNull(arr,
345
+ if (arr.length == 0 ) ArraySeq .empty[AnyRef ].asInstanceOf [ArraySeq .ofRef[T ]]
346
+ else ArraySeq .ofRef(arr.asInstanceOf [Array [T ]])
347
+ )
343
348
344
349
/** Conversion from IArray to immutable.ArraySeq */
345
350
implicit def wrapIntArray (arr : IArray [Int ]): ArraySeq .ofInt =
346
- if (arr ne null ) new ArraySeq .ofInt(arr.asInstanceOf [Array [Int ]]) else null
351
+ mapNull (arr, new ArraySeq .ofInt(arr.asInstanceOf [Array [Int ]]))
347
352
348
353
/** Conversion from IArray to immutable.ArraySeq */
349
354
implicit def wrapDoubleIArray (arr : IArray [Double ]): ArraySeq .ofDouble =
350
- if (arr ne null ) new ArraySeq .ofDouble(arr.asInstanceOf [Array [Double ]]) else null
355
+ mapNull (arr, new ArraySeq .ofDouble(arr.asInstanceOf [Array [Double ]]))
351
356
352
357
/** Conversion from IArray to immutable.ArraySeq */
353
358
implicit def wrapLongIArray (arr : IArray [Long ]): ArraySeq .ofLong =
354
- if (arr ne null ) new ArraySeq .ofLong(arr.asInstanceOf [Array [Long ]]) else null
359
+ mapNull (arr, new ArraySeq .ofLong(arr.asInstanceOf [Array [Long ]]))
355
360
356
361
/** Conversion from IArray to immutable.ArraySeq */
357
362
implicit def wrapFloatIArray (arr : IArray [Float ]): ArraySeq .ofFloat =
358
- if (arr ne null ) new ArraySeq .ofFloat(arr.asInstanceOf [Array [Float ]]) else null
363
+ mapNull (arr, new ArraySeq .ofFloat(arr.asInstanceOf [Array [Float ]]))
359
364
360
365
/** Conversion from IArray to immutable.ArraySeq */
361
366
implicit def wrapCharIArray (arr : IArray [Char ]): ArraySeq .ofChar =
362
- if (arr ne null ) new ArraySeq .ofChar(arr.asInstanceOf [Array [Char ]]) else null
367
+ mapNull (arr, new ArraySeq .ofChar(arr.asInstanceOf [Array [Char ]]))
363
368
364
369
/** Conversion from IArray to immutable.ArraySeq */
365
370
implicit def wrapByteIArray (arr : IArray [Byte ]): ArraySeq .ofByte =
366
- if (arr ne null ) new ArraySeq .ofByte(arr.asInstanceOf [Array [Byte ]]) else null
371
+ mapNull (arr, new ArraySeq .ofByte(arr.asInstanceOf [Array [Byte ]]))
367
372
368
373
/** Conversion from IArray to immutable.ArraySeq */
369
374
implicit def wrapShortIArray (arr : IArray [Short ]): ArraySeq .ofShort =
370
- if (arr ne null ) new ArraySeq .ofShort(arr.asInstanceOf [Array [Short ]]) else null
375
+ mapNull (arr, new ArraySeq .ofShort(arr.asInstanceOf [Array [Short ]]))
371
376
372
377
/** Conversion from IArray to immutable.ArraySeq */
373
378
implicit def wrapBooleanIArray (arr : IArray [Boolean ]): ArraySeq .ofBoolean =
374
- if (arr ne null ) new ArraySeq .ofBoolean(arr.asInstanceOf [Array [Boolean ]]) else null
379
+ mapNull (arr, new ArraySeq .ofBoolean(arr.asInstanceOf [Array [Boolean ]]))
375
380
376
381
/** Conversion from IArray to immutable.ArraySeq */
377
382
implicit def wrapUnitIArray (arr : IArray [Unit ]): ArraySeq .ofUnit =
378
- if (arr ne null ) new ArraySeq .ofUnit(arr.asInstanceOf [Array [Unit ]]) else null
383
+ mapNull (arr, new ArraySeq .ofUnit(arr.asInstanceOf [Array [Unit ]]))
379
384
380
385
/** Convert an array into an immutable array without copying, the original array
381
386
* must _not_ be mutated after this or the guaranteed immutablity of IArray will
0 commit comments