Skip to content

Pretend that BoxedUnit does not extend java.io.Serializable. #9454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ class Definitions {
cls
}
@tu lazy val ScalaPackageObject: Symbol = requiredModule("scala.package")
@tu lazy val ScalaRuntimePackageVal: TermSymbol = requiredPackage("scala.runtime")
@tu lazy val ScalaRuntimePackageClass: ClassSymbol = ScalaRuntimePackageVal.moduleClass.asClass
@tu lazy val JavaPackageVal: TermSymbol = requiredPackage(nme.java)
@tu lazy val JavaPackageClass: ClassSymbol = JavaPackageVal.moduleClass.asClass
@tu lazy val JavaLangPackageVal: TermSymbol = requiredPackage(jnme.JavaLang)
Expand Down Expand Up @@ -1098,6 +1100,9 @@ class Definitions {
def isTupleClass(cls: Symbol): Boolean = isVarArityClass(cls, str.Tuple)
def isProductClass(cls: Symbol): Boolean = isVarArityClass(cls, str.Product)

def isBoxedUnitClass(cls: Symbol): Boolean =
cls.isClass && (cls.owner eq ScalaRuntimePackageClass) && cls.name == tpnme.BoxedUnit

def isScalaShadowingPackageClass(cls: Symbol): Boolean =
cls.name == tpnme.scalaShadowing && cls.owner == RootClass

Expand Down Expand Up @@ -1314,6 +1319,11 @@ class Definitions {
else parents
}

/** If it is BoxedUnit, remove `java.io.Serializable` from `parents`. */
def adjustForBoxedUnit(cls: ClassSymbol, parents: List[Type]): List[Type] =
if (isBoxedUnitClass(cls)) parents.filter(_.typeSymbol != JavaSerializableClass)
else parents

private val HasProblematicGetClass: Set[Name] = Set(
tpnme.AnyVal, tpnme.Byte, tpnme.Short, tpnme.Char, tpnme.Int, tpnme.Long, tpnme.Float, tpnme.Double,
tpnme.Unit, tpnme.Boolean)
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/StdNames.scala
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ object StdNames {
final val Nil: N = "Nil"
final val Predef: N = "Predef"
final val ScalaRunTime: N = "ScalaRunTime"
final val BoxedUnit: N = "BoxedUnit"
final val Some: N = "Some"

val x_0 : N = "x$0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ object Scala2Unpickler {
val tempInfo = new TempClassInfo(denot.owner.thisType, cls, decls, ost)
denot.info = tempInfo // first rough info to avoid CyclicReferences
val parents1 = if (parents.isEmpty) defn.ObjectType :: Nil else parents.map(_.dealias)
// Add extra parents to the tuple classes from the standard library
// Adjust parents of the tuple classes and BoxedUnit from the standard library
// If from Scala 2, adjust for tuple classes; if not, it's from Java, and adjust for BoxedUnit
val normalizedParents =
if (fromScala2) defn.adjustForTuple(cls, tparams, parents1)
else parents1 // We are setting the info of a Java class, so it cannot be one of the tuple classes
else defn.adjustForBoxedUnit(cls, parents1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adjustment also needs to be done in the Namer (like adjustForTuple) since we typecheck BoxedUnit.java when compiling the standard library

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really how it works in Dotty? Because in scala/scala, BoxedUnit.java is compiled by Java first, and then its .class file is used when compiling the .scala sources of the stdlib. I don't think BoxedUnit.java is ever processed by scalac. Is the case with dotc?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's going to depend on how the project is built. I see the build.sbt of scala/scala sets compileOrder := CompileOrder.JavaThenScala but we don't do that in the dotty repo nor in our tests, so I wouldn't rely on it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Done ;)

for (tparam <- tparams) {
val tsym = decls.lookup(tparam.name)
if (tsym.exists) tsym.setFlag(TypeParam)
Expand Down
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,10 @@ class Namer { typer: Typer =>
denot.info = tempInfo

val parentTypes = defn.adjustForTuple(cls, cls.typeParams,
ensureFirstIsClass(parents.map(checkedParentType(_)), cls.span))
defn.adjustForBoxedUnit(cls,
ensureFirstIsClass(parents.map(checkedParentType(_)), cls.span)
)
)
typr.println(i"completing $denot, parents = $parents%, %, parentTypes = $parentTypes%, %")

if (impl.derived.nonEmpty) {
Expand Down
2 changes: 1 addition & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ object Build {
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/utils" ** "*.scala").get
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/junit" ** "*.scala").get
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/niobuffer" ** "*.scala").get
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/niocharset" ** (("*.scala": FileFilter) -- "BaseCharsetTest.scala" -- "Latin1Test.scala" -- "USASCIITest.scala" -- "UTF16Test.scala" -- "UTF8Test.scala")).get
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/niocharset" ** "*.scala").get
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/scalalib" ** (("*.scala": FileFilter) -- "EnumerationTest.scala" -- "SymbolTest.scala")).get
++ (dir / "shared/src/test/require-sam" ** "*.scala").get
++ (dir / "shared/src/test/require-jdk8/org/scalajs/testsuite/compiler" ** "*.scala").get
Expand Down