@@ -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
34713478object 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" )
0 commit comments