Skip to content

Commit 8016ed1

Browse files
committed
Scala.js: Fix Any.== for j.l.{Float,Double}.
This is a port of scala-js/scala-js@b7f3e23 in Scala.js upstream, which was itself a port to the JS back-end of scala/scala@6abb6ba in the Scala 2 JVM back-end. Together with the two parent commits, this fixes the `RegressionTest.scala` test suite, which we now enable.
1 parent 29a956d commit 8016ed1

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

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

Lines changed: 7 additions & 3 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

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)