Skip to content

Scala.js: Fix classOf[Null] and classOf[Nothing]. #9445

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
28 changes: 17 additions & 11 deletions compiler/src/dotty/tools/backend/sjs/JSEncoding.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ import dotty.tools.backend.jvm.DottyBackendInterface.symExtensions
*/
object JSEncoding {

private val ScalaNothingClassName = ClassName("scala.Nothing")
private val ScalaNullClassName = ClassName("scala.Null")
private val ScalaRuntimeNothingClassName = ClassName("scala.runtime.Nothing$")
private val ScalaRuntimeNullClassName = ClassName("scala.runtime.Null$")

// Fresh local name generator ----------------------------------------------

Expand Down Expand Up @@ -208,9 +208,9 @@ object JSEncoding {
/** Computes the type ref for a type, to be used in a method signature. */
private def paramOrResultTypeRef(tpe: Type)(using Context): jstpe.TypeRef = {
toTypeRef(tpe) match {
case jstpe.ClassRef(ScalaNullClassName) => jstpe.NullRef
case jstpe.ClassRef(ScalaNothingClassName) => jstpe.NothingRef
case otherTypeRef => otherTypeRef
case jstpe.ClassRef(ScalaRuntimeNullClassName) => jstpe.NullRef
case jstpe.ClassRef(ScalaRuntimeNothingClassName) => jstpe.NothingRef
case otherTypeRef => otherTypeRef
}
}

Expand Down Expand Up @@ -243,14 +243,20 @@ object JSEncoding {
if (sym.isAllOf(ModuleClass | JavaDefined)) sym.linkedClass
else sym

if (sym1 == defn.BoxedUnitClass) {
/* Rewire scala.runtime.BoxedUnit to java.lang.Void, as the IR expects.
* BoxedUnit$ is a JVM artifact.
*/
/* Some rewirings:
* - scala.runtime.BoxedUnit to java.lang.Void, as the IR expects.
* BoxedUnit$ is a JVM artifact.
* - scala.Nothing to scala.runtime.Nothing$.
* - scala.Null to scala.runtime.Null$.
*/
if (sym1 == defn.BoxedUnitClass)
ir.Names.BoxedUnitClass
} else {
else if (sym1 == defn.NothingClass)
ScalaRuntimeNothingClassName
else if (sym1 == defn.NullClass)
ScalaRuntimeNullClassName
else
ClassName(sym1.javaClassName)
}
}

def toIRType(tp: Type)(using Context): jstpe.Type = {
Expand Down
2 changes: 1 addition & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ object Build {
++ (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/scalalib" ** (("*.scala": FileFilter) -- "ArrayBuilderTest.scala" -- "ClassTagTest.scala" -- "EnumerationTest.scala" -- "SymbolTest.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": FileFilter) -- "DefaultMethodsTest.scala")).get
++ (dir / "shared/src/test/require-jdk8/org/scalajs/testsuite/javalib/lang" ** "*.scala").get
Expand Down