Skip to content

Running tests with munit and Scala.js breaks for Scala 3.7 #22794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Gedochao opened this issue Mar 13, 2025 · 4 comments
Closed

Running tests with munit and Scala.js breaks for Scala 3.7 #22794

Gedochao opened this issue Mar 13, 2025 · 4 comments
Assignees
Labels
area:scala.js itype:bug prio:blocker regression This worked in a previous version but doesn't anymore

Comments

@Gedochao
Copy link
Contributor

Gedochao commented Mar 13, 2025

Compiler version

Scala 3.7.0-RC1, 3.7.0-RC1-bin-20250312-3fe9304-NIGHTLY
Scala.js 1.18.2

Minimized code

//> using dep org.scalameta::munit::1.1.0
//> using platform js
//> using scala 3.7.0-RC1

class MyTests extends munit.FunSuite {
  test("foo") {
    assert(2 + 2 == 4)
  }
}

Output

scala test .
Compiling project (test, Scala 3.7.0-RC1, Scala.js 1.18.2)
Compiled project (test, Scala 3.7.0-RC1, Scala.js 1.18.2)
Referring to non-existent method scala.runtime.Arrays$.newArray(java.lang.Class,java.lang.Class,[int)java.lang.Object
  dispatched from scala.runtime.Arrays$.newArray(java.lang.Class,java.lang.Class,[int)java.lang.Object
  called from munit.internal.io.Files$.readAllBytes(munit.internal.io.MunitPath)[byte
  called from munit.internal.io.Files$.readAllLines(munit.internal.io.MunitPath)java.util.List
  called from munit.internal.io.PlatformIO$Files$.readAllLines(munit.internal.io.MunitPath)java.util.List
  called from private static munit.internal.console.Lines.$anonfun$1(munit.internal.io.MunitPath)[java.lang.String
  called from munit.internal.console.Lines.formatLine(munit.Location,java.lang.String,munit.Clues,boolean)java.lang.String
  called from munit.Assertions.fail(java.lang.String,munit.Clues,munit.Location,munit.diff.DiffOptions)nothing
  called from private munit.Assertions.assert$$anonfun$1(scala.Function0,scala.Function0,munit.Location)void
  called from private munit.Assertions.assert$$anonfun$adapted$1(scala.Function0,scala.Function0,munit.Location)java.lang.Object
  called from munit.Assertions.assert(scala.Function0,scala.Function0,munit.Location)void
  called from munit.FunSuite.assert(scala.Function0,scala.Function0,munit.Location)void
  dispatched from MyTests.assert(scala.Function0,scala.Function0,munit.Location)void
  called from private MyTests.$init$$$anonfun$1()java.lang.Object
  called from constructor MyTests.<init>()void
  called from static constructor MyTests.<stinit>()void
  called from core module analyzer
involving instantiated classes:
  munit.internal.io.Files$
  munit.internal.io.PlatformIO$Files$
  munit.internal.console.Lines
  MyTests
Exception in thread "main" org.scalajs.linker.interface.LinkingException: There were linking errors
        at org.scalajs.linker.analyzer.Analyzer.reportErrors(Analyzer.scala:92)
        at org.scalajs.linker.analyzer.Analyzer.$anonfun$computeReachability$1(Analyzer.scala:68)
        at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:467)
        at java.base@17.0.6/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1395)
        at java.base@17.0.6/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
        at java.base@17.0.6/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
        at java.base@17.0.6/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
        at java.base@17.0.6/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
        at java.base@17.0.6/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:775)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:203)
[error]  Error: main.js not found after Scala.js linking (no files found)

Expectation

Should run the tests with munit + Scala.js fine, as up to Scala 3.6.4.

scala test . -S 3.6.4    
Compiling project (test, Scala 3.6.4, Scala.js 1.18.2)
Compiled project (test, Scala 3.6.4, Scala.js 1.18.2)
MyTests:
  + foo 0.002s
@Gedochao Gedochao added area:scala.js itype:bug regression This worked in a previous version but doesn't anymore stat:needs bisection Need to use nightly builds and git bisect to find out the commit where this issue was introduced stat:needs minimization Needs a self contained minimization labels Mar 13, 2025
@sjrd
Copy link
Member

sjrd commented Mar 13, 2025

Looks like the same as scala-js/scala-js#5141 . I have a fix, but it's tricky to test.

@sjrd sjrd self-assigned this Mar 13, 2025
@Gedochao
Copy link
Contributor Author

Gedochao commented Mar 13, 2025

Last good release: 3.7.0-RC1-bin-20250124-f7e5df5-NIGHTLY
First bad release: 3.7.0-RC1-bin-20250127-89c20f8-NIGHTLY
2852168 is the first bad commit

@Gedochao Gedochao removed the stat:needs bisection Need to use nightly builds and git bisect to find out the commit where this issue was introduced label Mar 13, 2025
@sjrd sjrd added prio:blocker and removed stat:needs minimization Needs a self contained minimization labels Mar 13, 2025
@sjrd sjrd closed this as completed in 9c7193a Mar 13, 2025
sjrd added a commit that referenced this issue Mar 13, 2025
… 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.
WojciechMazur pushed a commit to WojciechMazur/dotty that referenced this issue Mar 13, 2025
… 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.
Gedochao added a commit that referenced this issue Mar 14, 2025
…#22796)

Example usage:

```bash
scala project/scripts/bisect.scala --jvm 17 -- --bootstrapped --releases 3.6.4-RC1-bin-20241120-bd07317-NIGHTLY... test smth.test.scala
```

`smth.test.scala`
```scala
//> using dep org.scalameta::munit::1.1.0
//> using platform js

class MyTests extends munit.FunSuite {
  test("foo") {
    assert(2 + 2 == 4)
  }
}
```

Allowed to bisect #22794
WojciechMazur added a commit that referenced this issue Mar 14, 2025
…ugh it's a primitive." to 3.7.0 (#22801)

Backports #22797 to Scala 3.7.0-RC2
@plokhotnyuk
Copy link

The similar error happens in jsoniter-scala project and can be easily reproduced with sbt ++3.7.0-RC1! jsoniter-scala-benchmarkJS/test command:

[error] Referring to non-existent method scala.runtime.Arrays$.newArray(java.lang.Class,java.lang.Class,[int)java.lang.Object
[error]   dispatched from scala.runtime.Arrays$.newArray(java.lang.Class,java.lang.Class,[int)java.lang.Object
[error]   called from org.scalatest.events.Ordinal.next()org.scalatest.events.Ordinal
[error]   called from org.scalatest.Tracker.nextOrdinal()org.scalatest.events.Ordinal
[error]   called from org.scalatest.tools.TaskRunner.executionFuture(sbt.testing.EventHandler,[sbt.testing.Logger)scala.concurrent.Future
[error]   called from org.scalatest.tools.TaskRunner.execute(sbt.testing.EventHandler,[sbt.testing.Logger,scala.Function1)void
[error]   dispatched from sbt.testing.Task.execute(sbt.testing.EventHandler,[sbt.testing.Logger,scala.Function1)void
[error]   called from private org.scalajs.testing.bridge.HTMLRunner$.scheduleTask(sbt.testing.Task,org.scalajs.testing.bridge.HTMLRunner$UI)scala.concurrent.Future
[error]   called from private static org.scalajs.testing.bridge.HTMLRunner$.runAllTasks$1(scala.collection.Seq,org.scalajs.testing.bridge.HTMLRunner$UI)scala.concurrent.Future
[error]   called from private org.scalajs.testing.bridge.HTMLRunner$.runTests(sbt.testing.Framework,scala.collection.immutable.Seq,org.scalajs.testing.bridge.HTMLRunner$UI)scala.concurrent.Future
[error]   called from private org.scalajs.testing.bridge.HTMLRunner$.onLoad(org.scalajs.testing.common.IsolatedTestSet)void
[error]   called from org.scalajs.testing.bridge.HTMLRunner$.start(org.scalajs.testing.common.IsolatedTestSet)void
[error]   called from org.scalajs.testing.bridge.Bridge$.start()void
[error]   called from static org.scalajs.testing.bridge.Bridge.start()void
[error]   called from core module module initializers
[error] involving instantiated classes:
[error]   org.scalatest.events.Ordinal
[error]   org.scalatest.Tracker
[error]   org.scalatest.tools.TaskRunner
[error]   org.scalajs.testing.bridge.HTMLRunner$
[error]   org.scalajs.testing.bridge.Bridge$
[error] There were linking errors
[error] (jsoniter-scala-benchmarkJS / Test / fastLinkJS) There were linking errors
[error] Total time: 79 s (0:01:19.0), completed Mar 15, 2025, 1:35:12 PM

@kubukoz
Copy link
Contributor

kubukoz commented Apr 3, 2025

I'm seeing the same as a user of Cats Effect. It happens in linking, no need to involve tests.

[error] Referring to non-existent method scala.runtime.Arrays$.newArray(java.lang.Class,java.lang.Class,[int)java.lang.Object
[error]   dispatched from scala.runtime.Arrays$.newArray(java.lang.Class,java.lang.Class,[int)java.lang.Object
[error]   called from constructor cats.effect.unsafe.StripedHashtable.<init>()void
[error]   called from constructor cats.effect.unsafe.IORuntime.<init>(scala.concurrent.ExecutionContext,scala.concurrent.ExecutionContext,cats.effect.unsafe.Scheduler,cats.effect.unsafe.FiberMonitor,scala.Function0,cats.effect.unsafe.IORuntimeConfig)void
[error]   called from cats.effect.unsafe.IORuntime$.apply(scala.concurrent.ExecutionContext,scala.concurrent.ExecutionContext,cats.effect.unsafe.Scheduler,scala.Function0,cats.effect.unsafe.IORuntimeConfig)cats.effect.unsafe.IORuntime
[error]   called from calico.unsafe.runtime$package$.given_IORuntime()cats.effect.unsafe.IORuntime
[error]   called from calico.IOWebApp.main([java.lang.String)void
[error]   called from com.kubukoz.stretchthekin.App$.main([java.lang.String)void
[error]   called from static com.kubukoz.stretchthekin.App.main([java.lang.String)void

Edit: oh, it's fixed - looking forward to a RC2 sometime, then! :)

tgodzik pushed a commit to scala/scala3-lts that referenced this issue Apr 7, 2025
… 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]
tgodzik pushed a commit to scala/scala3-lts that referenced this issue Apr 8, 2025
… 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]
tgodzik added a commit to scala/scala3-lts that referenced this issue Apr 8, 2025
Backport "Fix scala#22794: Emit the definition of `Arrays.newArray` even though it's a primitive." to 3.3 LTS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:scala.js itype:bug prio:blocker regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

No branches or pull requests

4 participants