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