@@ -326,7 +326,7 @@ object TypeErasure {
326
326
val sym = t.symbol
327
327
// Only a few classes have both primitives and references as subclasses.
328
328
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
330
330
NoSymbol
331
331
// We only need to check for primitives because derived value classes in arrays are always boxed.
332
332
else if sym.isPrimitiveValueClass then
@@ -596,8 +596,8 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
596
596
* will be returned.
597
597
*
598
598
* 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
601
601
* - otherwise, if T <: Object, []|T|
602
602
* - otherwise, if T is a type parameter coming from Java, []Object
603
603
* - otherwise, Object
@@ -781,12 +781,14 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
781
781
782
782
private def eraseArray (tp : Type )(using Context ) = {
783
783
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)
790
792
catch case ex : Throwable =>
791
793
handleRecursive(" erase array type" , tp.show, ex)
792
794
}
0 commit comments