Skip to content

Commit 8dae336

Browse files
committed
First step towards first-class Scala.js unions
Scala.js uses a magic trait to represent unions in Scala 2, we would like to unpickle these pseudo-unions as real OrTypes, but this requires erasing them like Scala 2 does. Now that we have a Scala 2 erasure mode this is actually possible and this commit adds the necessary erasure rule (the unpickling side and any change in the Scala.js phases is left as future work). Note that we really need to check both that we're in Scala 2 mode and that -scalajs is enabled, because a regular Scala 2 method type as seen from a Scala 3 prefix could contain unions after substitutions.
1 parent 7300868 commit 8dae336

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Symbols._, Types._, Contexts._, Flags._, Names._, StdNames._, Phases._
66
import Flags.JavaDefined
77
import Uniques.unique
88
import TypeOps.makePackageObjPrefixExplicit
9+
import backend.sjs.JSDefinitions
910
import transform.ExplicitOuter._
1011
import transform.ValueClasses._
1112
import transform.TypeUtils._
@@ -506,7 +507,10 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
506507
case AndType(tp1, tp2) =>
507508
erasedGlb(this(tp1), this(tp2), sourceLanguage.isJava)
508509
case OrType(tp1, tp2) =>
509-
TypeComparer.orType(this(tp1), this(tp2), isErased = true)
510+
if sourceLanguage.isScala2 && ctx.settings.scalajs.value then
511+
JSDefinitions.jsdefn.PseudoUnionType
512+
else
513+
TypeComparer.orType(this(tp1), this(tp2), isErased = true)
510514
case tp: MethodType =>
511515
def paramErasure(tpToErase: Type) =
512516
erasureFn(sourceLanguage, semiEraseVCs, isConstructor, wildcardOK)(tpToErase)

0 commit comments

Comments
 (0)