Skip to content

Commit 9940402

Browse files
Merge pull request #9630 from dotty-staging/sjs-fix-some-bugs
Scala.js: Fix 3 codegen bugs to enable `RegressionTest.scala`.
2 parents 239254a + 8016ed1 commit 9940402

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,13 +1838,17 @@ class JSCodeGen()(using genCtx: Context) {
18381838
* **which includes when either is a JS type**.
18391839
* When it is statically known that both sides are equal and subtypes of
18401840
* Number or Character, not using the rich equality is possible (their
1841-
* own equals method will do ok.)
1841+
* own equals method will do ok), except for java.lang.Float and
1842+
* java.lang.Double: their `equals` have different behavior around `NaN`
1843+
* and `-0.0`, see Javadoc (scala-dev#329, scala-js#2799).
18421844
*/
18431845
val mustUseAnyComparator: Boolean = {
18441846
isJSType(lsym) || isJSType(rsym) || {
18451847
val p = ctx.platform
1846-
val areSameFinals = lsym.is(Final) && rsym.is(Final) && (ltpe =:= rtpe)
1847-
!areSameFinals && p.isMaybeBoxed(lsym) && p.isMaybeBoxed(rsym)
1848+
p.isMaybeBoxed(lsym) && p.isMaybeBoxed(rsym) && {
1849+
val areSameFinals = lsym.is(Final) && rsym.is(Final) && (ltpe =:= rtpe)
1850+
!areSameFinals || lsym == defn.BoxedFloatClass || lsym == defn.BoxedDoubleClass
1851+
}
18481852
}
18491853
}
18501854

@@ -1976,10 +1980,11 @@ class JSCodeGen()(using genCtx: Context) {
19761980
genArg
19771981
case _ =>
19781982
implicit val pos = tree.span
1979-
/* TODO Check for a null receiver?
1980-
* In theory, it's UB, but that decision should be left for link time.
1981-
*/
1982-
js.Block(genReceiver, genArg)
1983+
js.Block(
1984+
js.If(js.BinaryOp(js.BinaryOp.===, genReceiver, js.Null()),
1985+
js.Throw(js.New(NullPointerExceptionClass, js.MethodIdent(jsNames.NoArgConstructorName), Nil)),
1986+
js.Skip())(jstpe.NoType),
1987+
genArg)
19831988
}
19841989
}
19851990

@@ -2277,9 +2282,11 @@ class JSCodeGen()(using genCtx: Context) {
22772282
abortMatch(s"Invalid selector type ${genSelector.tpe}")
22782283
}
22792284

2280-
val resultType =
2281-
if (isStat) jstpe.NoType
2282-
else toIRType(tree.tpe)
2285+
val resultType = toIRType(tree.tpe) match {
2286+
case jstpe.NothingType => jstpe.NothingType // must take priority over NoType below
2287+
case _ if isStat => jstpe.NoType
2288+
case resType => resType
2289+
}
22832290

22842291
var clauses: List[(List[js.Tree], js.Tree)] = Nil
22852292
var optDefaultClause: Option[js.Tree] = None
@@ -3470,6 +3477,7 @@ class JSCodeGen()(using genCtx: Context) {
34703477

34713478
object JSCodeGen {
34723479

3480+
private val NullPointerExceptionClass = ClassName("java.lang.NullPointerException")
34733481
private val JSObjectClassName = ClassName("scala.scalajs.js.Object")
34743482

34753483
private val newSimpleMethodName = SimpleMethodName("new")

project/Build.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,6 @@ object Build {
10211021
val dir = fetchScalaJSSource.value / "test-suite"
10221022
(
10231023
(dir / "shared/src/test/scala" ** (("*.scala": FileFilter)
1024-
-- "RegressionTest.scala" // IR checking errors
10251024
-- "ReflectiveCallTest.scala" // uses many forms of structural calls that are not allowed in Scala 3 anymore
10261025
-- "EnumerationTest.scala" // scala.Enumeration support for Scala.js is not implemented in dotc (yet)
10271026
-- "SymbolTest.scala" // uses the old literal symbol syntax, pending update upstream

0 commit comments

Comments
 (0)