@@ -328,54 +328,59 @@ object IArray:
328328 extension [T , U >: T : ClassTag ](x : T )
329329 def +: (arr : IArray [U ]): IArray [U ] = genericArrayOps(arr).prepended(x)
330330
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+
331335 /** Conversion from IArray to immutable.ArraySeq */
332336 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) )
334338
335339 /** Conversion from IArray to immutable.ArraySeq */
336340 implicit def wrapRefArray [T <: AnyRef ](arr : IArray [T ]): ArraySeq .ofRef[T ] =
337341 // Since the JVM thinks arrays are covariant, one 0-length Array[AnyRef]
338342 // is as good as another for all T <: AnyRef. Instead of creating 100,000,000
339343 // 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+ )
343348
344349 /** Conversion from IArray to immutable.ArraySeq */
345350 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 ]]))
347352
348353 /** Conversion from IArray to immutable.ArraySeq */
349354 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 ]]))
351356
352357 /** Conversion from IArray to immutable.ArraySeq */
353358 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 ]]))
355360
356361 /** Conversion from IArray to immutable.ArraySeq */
357362 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 ]]))
359364
360365 /** Conversion from IArray to immutable.ArraySeq */
361366 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 ]]))
363368
364369 /** Conversion from IArray to immutable.ArraySeq */
365370 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 ]]))
367372
368373 /** Conversion from IArray to immutable.ArraySeq */
369374 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 ]]))
371376
372377 /** Conversion from IArray to immutable.ArraySeq */
373378 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 ]]))
375380
376381 /** Conversion from IArray to immutable.ArraySeq */
377382 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 ]]))
379384
380385 /** Convert an array into an immutable array without copying, the original array
381386 * must _not_ be mutated after this or the guaranteed immutablity of IArray will
0 commit comments