@@ -1838,13 +1838,17 @@ class JSCodeGen()(using genCtx: Context) {
1838
1838
* **which includes when either is a JS type**.
1839
1839
* When it is statically known that both sides are equal and subtypes of
1840
1840
* 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).
1842
1844
*/
1843
1845
val mustUseAnyComparator : Boolean = {
1844
1846
isJSType(lsym) || isJSType(rsym) || {
1845
1847
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
+ }
1848
1852
}
1849
1853
}
1850
1854
@@ -1976,10 +1980,11 @@ class JSCodeGen()(using genCtx: Context) {
1976
1980
genArg
1977
1981
case _ =>
1978
1982
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)
1983
1988
}
1984
1989
}
1985
1990
@@ -2277,9 +2282,11 @@ class JSCodeGen()(using genCtx: Context) {
2277
2282
abortMatch(s " Invalid selector type ${genSelector.tpe}" )
2278
2283
}
2279
2284
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
+ }
2283
2290
2284
2291
var clauses : List [(List [js.Tree ], js.Tree )] = Nil
2285
2292
var optDefaultClause : Option [js.Tree ] = None
@@ -3470,6 +3477,7 @@ class JSCodeGen()(using genCtx: Context) {
3470
3477
3471
3478
object JSCodeGen {
3472
3479
3480
+ private val NullPointerExceptionClass = ClassName (" java.lang.NullPointerException" )
3473
3481
private val JSObjectClassName = ClassName (" scala.scalajs.js.Object" )
3474
3482
3475
3483
private val newSimpleMethodName = SimpleMethodName (" new" )
0 commit comments