@@ -683,7 +683,15 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
683683 if e1.isInstanceOf [WildcardType ] || e2.isInstanceOf [WildcardType ] then WildcardType
684684 else erasedGlb(e1, e2)
685685 case OrType (tp1, tp2) =>
686- if isSymbol && sourceLanguage.isScala2 && ctx.settings.scalajs.value then
686+ val e1 = this (tp1)
687+ val e2 = this (tp2)
688+ val result = if e1.isInstanceOf [WildcardType ] || e2.isInstanceOf [WildcardType ]
689+ then WildcardType
690+ else TypeComparer .orType(e1, e2, isErased = true )
691+ def isNullStripped =
692+ tp2.isNullType && e1.derivesFrom(defn.ObjectClass )
693+ || tp1.isNullType && e2.derivesFrom(defn.ObjectClass )
694+ if isSymbol && sourceLanguage.isScala2 && ctx.settings.scalajs.value && ! isNullStripped then
687695 // In Scala2Unpickler we unpickle Scala.js pseudo-unions as if they were
688696 // real unions, but we must still erase them as Scala 2 would to emit
689697 // the correct signatures in SJSIR.
@@ -694,11 +702,7 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
694702 // impact on overriding relationships so it's best to leave them
695703 // alone (and this doesn't impact the SJSIR we generate).
696704 JSDefinitions .jsdefn.PseudoUnionType
697- else
698- val e1 = this (tp1)
699- val e2 = this (tp2)
700- if e1.isInstanceOf [WildcardType ] || e2.isInstanceOf [WildcardType ] then WildcardType
701- else TypeComparer .orType(e1, e2, isErased = true )
705+ else result
702706 case tp : MethodType =>
703707 def paramErasure (tpToErase : Type ) =
704708 erasureFn(sourceLanguage, semiEraseVCs, isConstructor, isSymbol, inSigName = false )(tpToErase)
0 commit comments