Skip to content

Commit f77b1f9

Browse files
committed
fix: align Scala 2's erasure of Array[? <: Null] and Array[? <: Nothing] with Scala 2
1 parent da06de5 commit f77b1f9

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

compiler/src/dotty/tools/dotc/core/TypeErasure.scala

+9-9
Original file line numberDiff line numberDiff line change
@@ -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
@@ -781,14 +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-
if sourceLanguage.isScala2 && (elemtp.isNullType || elemtp.isNothingType) then
788-
JavaArrayType(defn.ObjectType)
789-
else erasureFn(sourceLanguage, semiEraseVCs = false, isConstructor, isSymbol, inSigName)(elemtp) match
790-
case _: WildcardType => WildcardType
791-
case elem => JavaArrayType(elem)
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)
792792
catch case ex: Throwable =>
793793
handleRecursive("erase array type", tp.show, ex)
794794
}

sbt-test/scala2-compat/erasure/dottyApp/Main.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ object Main {
103103
z.objectARRAY_90(dummy)
104104
z.objectARRAY_91(dummy)
105105
z.objectARRAY_92(dummy)
106-
//z.objectARRAY_93(dummy)
107-
//z.objectARRAY_94(dummy)
106+
z.objectARRAY_93(dummy)
107+
z.objectARRAY_94(dummy)
108108

109109
val methods = classOf[scala2Lib.Z].getDeclaredMethods.toList ++ classOf[dottyApp.Z].getDeclaredMethods.toList
110110
methods.foreach { m =>

0 commit comments

Comments
 (0)