Skip to content

Commit b646238

Browse files
sjrdtgodzik
authored andcommitted
Fix scala#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. [Cherry-picked 9c7193a]
1 parent 64fb8d6 commit b646238

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
@@ -1496,7 +1496,7 @@ class JSCodeGen()(using genCtx: Context) {
14961496

14971497
def jsParams = params.map(genParamDef(_))
14981498

1499-
if (primitives.isPrimitive(sym)) {
1499+
if (primitives.isPrimitive(sym) && sym != defn.newArrayMethod) {
15001500
None
15011501
} else if (sym.is(Deferred) && currentClassSym.isNonNativeJSClass) {
15021502
// 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.0.0-M10"
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)