@@ -326,7 +326,7 @@ object TypeErasure {
326326 val sym = t.symbol
327327 // Only a few classes have both primitives and references as subclasses.
328328 if (sym eq defn.AnyClass ) || (sym eq defn.AnyValClass ) || (sym eq defn.MatchableClass ) || (sym eq defn.SingletonClass )
329- || isScala2 && ! (t.derivesFrom(defn.ObjectClass ) || t.isNullType) then
329+ || isScala2 && ! (t.derivesFrom(defn.ObjectClass ) || t.isNullType | t.isNothingType ) then
330330 NoSymbol
331331 // We only need to check for primitives because derived value classes in arrays are always boxed.
332332 else if sym.isPrimitiveValueClass then
@@ -596,8 +596,8 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
596596 * will be returned.
597597 *
598598 * In all other situations, |T| will be computed as follow:
599- * - For a refined type scala.Array+ [T]:
600- * - if T is Nothing or Null, []Object
599+ * - For a refined type scala.Array[T]:
600+ * - {Scala 2} if T is Nothing or Null, []Object
601601 * - otherwise, if T <: Object, []|T|
602602 * - otherwise, if T is a type parameter coming from Java, []Object
603603 * - otherwise, Object
@@ -781,12 +781,14 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
781781
782782 private def eraseArray (tp : Type )(using Context ) = {
783783 val defn .ArrayOf (elemtp) = tp : @ unchecked
784- if (isGenericArrayElement(elemtp, isScala2 = sourceLanguage.isScala2)) defn.ObjectType
785- else
786- try
787- val eElem = erasureFn(sourceLanguage, semiEraseVCs = false , isConstructor, isSymbol, inSigName)(elemtp)
788- if eElem.isInstanceOf [WildcardType ] then WildcardType
789- else JavaArrayType (eElem)
784+ if isGenericArrayElement(elemtp, isScala2 = sourceLanguage.isScala2) then
785+ defn.ObjectType
786+ else if sourceLanguage.isScala2 && (elemtp.hiBound.isNullType || elemtp.hiBound.isNothingType) then
787+ JavaArrayType (defn.ObjectType )
788+ else
789+ try erasureFn(sourceLanguage, semiEraseVCs = false , isConstructor, isSymbol, inSigName)(elemtp) match
790+ case _ : WildcardType => WildcardType
791+ case elem => JavaArrayType (elem)
790792 catch case ex : Throwable =>
791793 handleRecursive(" erase array type" , tp.show, ex)
792794 }
0 commit comments