Skip to content

Commit bc4b401

Browse files
authored
Merge pull request #9454 from sjrd/scalajs-fix-unit-not-serializable-ir-error
Pretend that BoxedUnit does not extend java.io.Serializable.
2 parents 2ff15be + 1bd7d2e commit bc4b401

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ class Definitions {
210210
cls
211211
}
212212
@tu lazy val ScalaPackageObject: Symbol = requiredModule("scala.package")
213+
@tu lazy val ScalaRuntimePackageVal: TermSymbol = requiredPackage("scala.runtime")
214+
@tu lazy val ScalaRuntimePackageClass: ClassSymbol = ScalaRuntimePackageVal.moduleClass.asClass
213215
@tu lazy val JavaPackageVal: TermSymbol = requiredPackage(nme.java)
214216
@tu lazy val JavaPackageClass: ClassSymbol = JavaPackageVal.moduleClass.asClass
215217
@tu lazy val JavaLangPackageVal: TermSymbol = requiredPackage(jnme.JavaLang)
@@ -1098,6 +1100,9 @@ class Definitions {
10981100
def isTupleClass(cls: Symbol): Boolean = isVarArityClass(cls, str.Tuple)
10991101
def isProductClass(cls: Symbol): Boolean = isVarArityClass(cls, str.Product)
11001102

1103+
def isBoxedUnitClass(cls: Symbol): Boolean =
1104+
cls.isClass && (cls.owner eq ScalaRuntimePackageClass) && cls.name == tpnme.BoxedUnit
1105+
11011106
def isScalaShadowingPackageClass(cls: Symbol): Boolean =
11021107
cls.name == tpnme.scalaShadowing && cls.owner == RootClass
11031108

@@ -1314,6 +1319,11 @@ class Definitions {
13141319
else parents
13151320
}
13161321

1322+
/** If it is BoxedUnit, remove `java.io.Serializable` from `parents`. */
1323+
def adjustForBoxedUnit(cls: ClassSymbol, parents: List[Type]): List[Type] =
1324+
if (isBoxedUnitClass(cls)) parents.filter(_.typeSymbol != JavaSerializableClass)
1325+
else parents
1326+
13171327
private val HasProblematicGetClass: Set[Name] = Set(
13181328
tpnme.AnyVal, tpnme.Byte, tpnme.Short, tpnme.Char, tpnme.Int, tpnme.Long, tpnme.Float, tpnme.Double,
13191329
tpnme.Unit, tpnme.Boolean)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ object StdNames {
306306
final val Nil: N = "Nil"
307307
final val Predef: N = "Predef"
308308
final val ScalaRunTime: N = "ScalaRunTime"
309+
final val BoxedUnit: N = "BoxedUnit"
309310
final val Some: N = "Some"
310311

311312
val x_0 : N = "x$0"

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,11 @@ object Scala2Unpickler {
9898
val tempInfo = new TempClassInfo(denot.owner.thisType, cls, decls, ost)
9999
denot.info = tempInfo // first rough info to avoid CyclicReferences
100100
val parents1 = if (parents.isEmpty) defn.ObjectType :: Nil else parents.map(_.dealias)
101-
// Add extra parents to the tuple classes from the standard library
101+
// Adjust parents of the tuple classes and BoxedUnit from the standard library
102+
// If from Scala 2, adjust for tuple classes; if not, it's from Java, and adjust for BoxedUnit
102103
val normalizedParents =
103104
if (fromScala2) defn.adjustForTuple(cls, tparams, parents1)
104-
else parents1 // We are setting the info of a Java class, so it cannot be one of the tuple classes
105+
else defn.adjustForBoxedUnit(cls, parents1)
105106
for (tparam <- tparams) {
106107
val tsym = decls.lookup(tparam.name)
107108
if (tsym.exists) tsym.setFlag(TypeParam)

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,10 @@ class Namer { typer: Typer =>
11701170
denot.info = tempInfo
11711171

11721172
val parentTypes = defn.adjustForTuple(cls, cls.typeParams,
1173-
ensureFirstIsClass(parents.map(checkedParentType(_)), cls.span))
1173+
defn.adjustForBoxedUnit(cls,
1174+
ensureFirstIsClass(parents.map(checkedParentType(_)), cls.span)
1175+
)
1176+
)
11741177
typr.println(i"completing $denot, parents = $parents%, %, parentTypes = $parentTypes%, %")
11751178

11761179
if (impl.derived.nonEmpty) {

project/Build.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ object Build {
10541054
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/utils" ** "*.scala").get
10551055
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/junit" ** "*.scala").get
10561056
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/niobuffer" ** "*.scala").get
1057-
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/niocharset" ** (("*.scala": FileFilter) -- "BaseCharsetTest.scala" -- "Latin1Test.scala" -- "USASCIITest.scala" -- "UTF16Test.scala" -- "UTF8Test.scala")).get
1057+
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/niocharset" ** "*.scala").get
10581058
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/scalalib" ** (("*.scala": FileFilter) -- "EnumerationTest.scala" -- "SymbolTest.scala")).get
10591059
++ (dir / "shared/src/test/require-sam" ** "*.scala").get
10601060
++ (dir / "shared/src/test/require-jdk8/org/scalajs/testsuite/compiler" ** "*.scala").get

0 commit comments

Comments
 (0)