Skip to content

Commit 9c7193a

Browse files
committed
Fix #22794: Emit the definition of Arrays.newArray even though it's a primitive.
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.
1 parent a986531 commit 9c7193a

File tree

5 files changed

+14
-1
lines changed

5 files changed

+14
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
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
Lines changed: 5 additions & 0 deletions
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"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % sys.props("plugin.scalaJSVersion"))
Lines changed: 5 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
> test

0 commit comments

Comments
 (0)