Skip to content

Commit 596538b

Browse files
authored
Fix #22794: Emit the definition of Arrays.newArray even though it's a primitive. (#22797)
Until 3.6.x, we used the user-space definition of `Arrays.newArray` in Scala.js. We changed it to a primitve in 2852168, to match the behavior of the JVM backend. However, that had the side effect of not emitting its definition at all, like other primitives. For backward binary compat reasons, we do need that definition. We specifically make an exception for that method, which is now emitted, even though it is otherwise treated as a primitive.
2 parents a986531 + 9c7193a commit 596538b

File tree

5 files changed

+14
-1
lines changed

5 files changed

+14
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@ class JSCodeGen()(using genCtx: Context) {
15571557

15581558
def jsParams = params.map(genParamDef(_))
15591559

1560-
if (primitives.isPrimitive(sym)) {
1560+
if (primitives.isPrimitive(sym) && sym != defn.newArrayMethod) {
15611561
None
15621562
} else if (sym.is(Deferred) && currentClassSym.isNonNativeJSClass) {
15631563
// scala-js/#4409: Do not emit abstract methods in non-native JS classes
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
enablePlugins(ScalaJSPlugin)
2+
3+
scalaVersion := sys.props("plugin.scalaVersion")
4+
5+
libraryDependencies += "org.scalameta" %%% "munit" % "1.1.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % sys.props("plugin.scalaJSVersion"))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class NewArrayIssue22794Test extends munit.FunSuite {
2+
test("foo") {
3+
assert(2 + 2 == 4)
4+
}
5+
}

sbt-test/scalajs/backward-compat/test

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
> test

0 commit comments

Comments
 (0)