Skip to content

Commit

Permalink
fix: align Scala 2's erasure of Array[? <: Null] and Array[? <: Nothi…
Browse files Browse the repository at this point in the history
…ng] with Scala 2
  • Loading branch information
hamzaremmal committed Feb 5, 2025
1 parent da06de5 commit f77b1f9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
18 changes: 9 additions & 9 deletions compiler/src/dotty/tools/dotc/core/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ object TypeErasure {
val sym = t.symbol
// Only a few classes have both primitives and references as subclasses.
if (sym eq defn.AnyClass) || (sym eq defn.AnyValClass) || (sym eq defn.MatchableClass) || (sym eq defn.SingletonClass)
|| isScala2 && !(t.derivesFrom(defn.ObjectClass) || t.isNullType) then
|| isScala2 && !(t.derivesFrom(defn.ObjectClass) || t.isNullType | t.isNothingType) then
NoSymbol
// We only need to check for primitives because derived value classes in arrays are always boxed.
else if sym.isPrimitiveValueClass then
Expand Down Expand Up @@ -781,14 +781,14 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst

private def eraseArray(tp: Type)(using Context) = {
val defn.ArrayOf(elemtp) = tp: @unchecked
if (isGenericArrayElement(elemtp, isScala2 = sourceLanguage.isScala2)) defn.ObjectType
else
try
if sourceLanguage.isScala2 && (elemtp.isNullType || elemtp.isNothingType) then
JavaArrayType(defn.ObjectType)
else erasureFn(sourceLanguage, semiEraseVCs = false, isConstructor, isSymbol, inSigName)(elemtp) match
case _: WildcardType => WildcardType
case elem => JavaArrayType(elem)
if isGenericArrayElement(elemtp, isScala2 = sourceLanguage.isScala2) then
defn.ObjectType
else if sourceLanguage.isScala2 && (elemtp.hiBound.isNullType || elemtp.hiBound.isNothingType) then
JavaArrayType(defn.ObjectType)
else
try erasureFn(sourceLanguage, semiEraseVCs = false, isConstructor, isSymbol, inSigName)(elemtp) match
case _: WildcardType => WildcardType
case elem => JavaArrayType(elem)
catch case ex: Throwable =>
handleRecursive("erase array type", tp.show, ex)
}
Expand Down
4 changes: 2 additions & 2 deletions sbt-test/scala2-compat/erasure/dottyApp/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ object Main {
z.objectARRAY_90(dummy)
z.objectARRAY_91(dummy)
z.objectARRAY_92(dummy)
//z.objectARRAY_93(dummy)
//z.objectARRAY_94(dummy)
z.objectARRAY_93(dummy)
z.objectARRAY_94(dummy)

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

0 comments on commit f77b1f9

Please sign in to comment.