@@ -656,47 +656,49 @@ private[scala] abstract class LowPriorityImplicits extends LowPriorityImplicits2
656656 @ inline implicit def doubleWrapper (x : Double ): runtime.RichDouble = new runtime.RichDouble (x)
657657 @ inline implicit def booleanWrapper (x : Boolean ): runtime.RichBoolean = new runtime.RichBoolean (x)
658658
659+ // For backwards compatibility with code compiled without -Yexplicit-nulls
660+ private inline def mapNull [A , B ](a : A , inline f : B ): B =
661+ if ((a : A | Null ) == null ) null .asInstanceOf [B ] else f
662+
659663 /** @group conversions-array-to-wrapped-array */
660- implicit def genericWrapArray [T ](xs : Array [T ] | Null ): ArraySeq [T ] | Null =
661- if (xs eq null ) null
662- else ArraySeq .make(xs)
664+ implicit def genericWrapArray [T ](xs : Array [T ]): ArraySeq [T ] =
665+ mapNull(xs, ArraySeq .make(xs))
663666
664667 // Since the JVM thinks arrays are covariant, one 0-length Array[AnyRef]
665668 // is as good as another for all T <: AnyRef. Instead of creating 100,000,000
666669 // unique ones by way of this implicit, let's share one.
667670 /** @group conversions-array-to-wrapped-array */
668- implicit def wrapRefArray [T <: AnyRef ](xs : Array [T ] | Null ): ArraySeq .ofRef[T ] | Null = {
669- if (xs eq null ) null
670- else if (xs.length == 0 ) ArraySeq .empty[AnyRef ].asInstanceOf [ArraySeq .ofRef[T ]]
671- else new ArraySeq .ofRef[T ](xs)
672- }
671+ implicit def wrapRefArray [T <: AnyRef | Null ](xs : Array [T ]): ArraySeq .ofRef[T ] =
672+ mapNull(xs,
673+ if (xs.length == 0 ) ArraySeq .empty[AnyRef ].asInstanceOf [ArraySeq .ofRef[T ]]
674+ else new ArraySeq .ofRef[T ](xs))
673675
674676 /** @group conversions-array-to-wrapped-array */
675- implicit def wrapIntArray (xs : Array [Int ] | Null ): ArraySeq .ofInt | Null = if (xs ne null ) new ArraySeq .ofInt(xs) else null
677+ implicit def wrapIntArray (xs : Array [Int ]): ArraySeq .ofInt = mapNull (xs, new ArraySeq .ofInt(xs))
676678 /** @group conversions-array-to-wrapped-array */
677- implicit def wrapDoubleArray (xs : Array [Double ] | Null ): ArraySeq .ofDouble | Null = if (xs ne null ) new ArraySeq .ofDouble(xs) else null
679+ implicit def wrapDoubleArray (xs : Array [Double ]): ArraySeq .ofDouble = mapNull (xs, new ArraySeq .ofDouble(xs))
678680 /** @group conversions-array-to-wrapped-array */
679- implicit def wrapLongArray (xs : Array [Long ] | Null ): ArraySeq .ofLong | Null = if (xs ne null ) new ArraySeq .ofLong(xs) else null
681+ implicit def wrapLongArray (xs : Array [Long ]): ArraySeq .ofLong = mapNull (xs, new ArraySeq .ofLong(xs))
680682 /** @group conversions-array-to-wrapped-array */
681- implicit def wrapFloatArray (xs : Array [Float ] | Null ): ArraySeq .ofFloat | Null = if (xs ne null ) new ArraySeq .ofFloat(xs) else null
683+ implicit def wrapFloatArray (xs : Array [Float ]): ArraySeq .ofFloat = mapNull (xs, new ArraySeq .ofFloat(xs))
682684 /** @group conversions-array-to-wrapped-array */
683- implicit def wrapCharArray (xs : Array [Char ] | Null ): ArraySeq .ofChar | Null = if (xs ne null ) new ArraySeq .ofChar(xs) else null
685+ implicit def wrapCharArray (xs : Array [Char ]): ArraySeq .ofChar = mapNull (xs, new ArraySeq .ofChar(xs))
684686 /** @group conversions-array-to-wrapped-array */
685- implicit def wrapByteArray (xs : Array [Byte ] | Null ): ArraySeq .ofByte | Null = if (xs ne null ) new ArraySeq .ofByte(xs) else null
687+ implicit def wrapByteArray (xs : Array [Byte ]): ArraySeq .ofByte = mapNull (xs, new ArraySeq .ofByte(xs))
686688 /** @group conversions-array-to-wrapped-array */
687- implicit def wrapShortArray (xs : Array [Short ] | Null ): ArraySeq .ofShort | Null = if (xs ne null ) new ArraySeq .ofShort(xs) else null
689+ implicit def wrapShortArray (xs : Array [Short ]): ArraySeq .ofShort = mapNull (xs, new ArraySeq .ofShort(xs))
688690 /** @group conversions-array-to-wrapped-array */
689- implicit def wrapBooleanArray (xs : Array [Boolean ] | Null ): ArraySeq .ofBoolean | Null = if (xs ne null ) new ArraySeq .ofBoolean(xs) else null
691+ implicit def wrapBooleanArray (xs : Array [Boolean ]): ArraySeq .ofBoolean = mapNull (xs, new ArraySeq .ofBoolean(xs))
690692 /** @group conversions-array-to-wrapped-array */
691- implicit def wrapUnitArray (xs : Array [Unit ] | Null ): ArraySeq .ofUnit | Null = if (xs ne null ) new ArraySeq .ofUnit(xs) else null
693+ implicit def wrapUnitArray (xs : Array [Unit ]): ArraySeq .ofUnit = mapNull (xs, new ArraySeq .ofUnit(xs))
692694
693695 /** @group conversions-string */
694- implicit def wrapString (s : String | Null ): WrappedString | Null = if (s ne null ) new WrappedString (s) else null
696+ implicit def wrapString (s : String ): WrappedString = mapNull(s, new WrappedString (s))
695697}
696698
697699private [scala] abstract class LowPriorityImplicits2 {
698700 @ 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" )
699- implicit def copyArrayToImmutableIndexedSeq [T ](xs : Array [T ] | Null ): IndexedSeq [T ] | Null =
700- if (xs eq null ) null
701+ implicit def copyArrayToImmutableIndexedSeq [T ](xs : Array [T ]): IndexedSeq [T ] =
702+ if (xs eq null ) null . asInstanceOf [ IndexedSeq [ T ]]
701703 else new ArrayOps (xs).toIndexedSeq
702704}
0 commit comments