Skip to content

Commit 5665300

Browse files
committed
Modify type erasure logic of nullable unions for Scala 2 pseudo-unions in TypeErasure
1 parent 71fcd1a commit 5665300

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,15 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
681681
if e1.isInstanceOf[WildcardType] || e2.isInstanceOf[WildcardType] then WildcardType
682682
else erasedGlb(e1, e2)
683683
case OrType(tp1, tp2) =>
684-
if isSymbol && sourceLanguage.isScala2 && ctx.settings.scalajs.value then
684+
val e1 = this(tp1)
685+
val e2 = this(tp2)
686+
val result = if e1.isInstanceOf[WildcardType] || e2.isInstanceOf[WildcardType]
687+
then WildcardType
688+
else TypeComparer.orType(e1, e2, isErased = true)
689+
def isNullStripped =
690+
tp2.isNullType && e1.derivesFrom(defn.ObjectClass)
691+
|| tp1.isNullType && e2.derivesFrom(defn.ObjectClass)
692+
if isSymbol && sourceLanguage.isScala2 && ctx.settings.scalajs.value && !isNullStripped then
685693
// In Scala2Unpickler we unpickle Scala.js pseudo-unions as if they were
686694
// real unions, but we must still erase them as Scala 2 would to emit
687695
// the correct signatures in SJSIR.
@@ -692,11 +700,7 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
692700
// impact on overriding relationships so it's best to leave them
693701
// alone (and this doesn't impact the SJSIR we generate).
694702
JSDefinitions.jsdefn.PseudoUnionType
695-
else
696-
val e1 = this(tp1)
697-
val e2 = this(tp2)
698-
if e1.isInstanceOf[WildcardType] || e2.isInstanceOf[WildcardType] then WildcardType
699-
else TypeComparer.orType(e1, e2, isErased = true)
703+
else result
700704
case tp: MethodType =>
701705
def paramErasure(tpToErase: Type) =
702706
erasureFn(sourceLanguage, semiEraseVCs, isConstructor, isSymbol, inSigName = false)(tpToErase)

0 commit comments

Comments
 (0)