@@ -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
698700private [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}
0 commit comments