Skip to content

Commit ec50bcf

Browse files
authored
Merge pull request #9445 from sjrd/scalajs-fix-classof-null-nothing
Scala.js: Fix `classOf[Null]` and `classOf[Nothing]`.
2 parents 8c32f45 + 5de1340 commit ec50bcf

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

compiler/src/dotty/tools/backend/sjs/JSEncoding.scala

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ import dotty.tools.backend.jvm.DottyBackendInterface.symExtensions
4343
*/
4444
object JSEncoding {
4545

46-
private val ScalaNothingClassName = ClassName("scala.Nothing")
47-
private val ScalaNullClassName = ClassName("scala.Null")
46+
private val ScalaRuntimeNothingClassName = ClassName("scala.runtime.Nothing$")
47+
private val ScalaRuntimeNullClassName = ClassName("scala.runtime.Null$")
4848

4949
// Fresh local name generator ----------------------------------------------
5050

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

@@ -243,14 +243,20 @@ object JSEncoding {
243243
if (sym.isAllOf(ModuleClass | JavaDefined)) sym.linkedClass
244244
else sym
245245

246-
if (sym1 == defn.BoxedUnitClass) {
247-
/* Rewire scala.runtime.BoxedUnit to java.lang.Void, as the IR expects.
248-
* BoxedUnit$ is a JVM artifact.
249-
*/
246+
/* Some rewirings:
247+
* - scala.runtime.BoxedUnit to java.lang.Void, as the IR expects.
248+
* BoxedUnit$ is a JVM artifact.
249+
* - scala.Nothing to scala.runtime.Nothing$.
250+
* - scala.Null to scala.runtime.Null$.
251+
*/
252+
if (sym1 == defn.BoxedUnitClass)
250253
ir.Names.BoxedUnitClass
251-
} else {
254+
else if (sym1 == defn.NothingClass)
255+
ScalaRuntimeNothingClassName
256+
else if (sym1 == defn.NullClass)
257+
ScalaRuntimeNullClassName
258+
else
252259
ClassName(sym1.javaClassName)
253-
}
254260
}
255261

256262
def toIRType(tp: Type)(using Context): jstpe.Type = {

project/Build.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ object Build {
10551055
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/junit" ** "*.scala").get
10561056
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/niobuffer" ** "*.scala").get
10571057
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/niocharset" ** (("*.scala": FileFilter) -- "BaseCharsetTest.scala" -- "Latin1Test.scala" -- "USASCIITest.scala" -- "UTF16Test.scala" -- "UTF8Test.scala")).get
1058-
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/scalalib" ** (("*.scala": FileFilter) -- "ArrayBuilderTest.scala" -- "ClassTagTest.scala" -- "EnumerationTest.scala" -- "SymbolTest.scala")).get
1058+
++ (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": FileFilter) -- "DefaultMethodsTest.scala")).get
10611061
++ (dir / "shared/src/test/require-jdk8/org/scalajs/testsuite/javalib/lang" ** "*.scala").get

0 commit comments

Comments
 (0)