Skip to content

Add a Scala.js example to the wasm corpus and fix none subtyping - #314

Merged
andreaTP merged 2 commits into
bytecodealliance:mainfrom
andreaTP:scalajs-corpus
Nov 18, 2026
Merged

andreaTP merged 2 commits into
bytecodealliance:mainfrom
andreaTP:scalajs-corpus

Conversation

@andreaTP

@andreaTP andreaTP commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Scala.js 1.23.0 can emit a bare Wasm module (ModuleKind.WasmModule), with no JS glue and no WASI. This adds a hello world built that way to the corpus and runs it in MachinesTest, interpreted and compiled.

The module needs GC, exceptions and tail calls. System.out doesn't link in this mode, so the program declares env.print(Array[Byte]) with @WasmImport, and the test's host function reads the bytes from the WasmArray it receives. main runs as the start function.

Validating the module exposed a bug: the none case of heapTypeSubtype had its arguments swapped, checking any <: ht instead of ht <: any. So ref.null none was rejected wherever eq, i31, struct or array was expected; Scala.js hits this when it fills structref fields with nulls. It now follows the spec rule: none <: ht if ht <: any.

Other changes:

  • compile.sh has a scalajs target, and the corpus image installs sbt.
  • WasmWriterTest skips the module: the Scala.js linker pads section sizes to 4 bytes, like the Go and Kotlin modules that are already skipped.

Testing:

  • New none.wat corpus module with NoneTest, which runs every export on the interpreter and the compiler. It fails on main.
  • New MachinesTest.shouldRunScalaJsWasmInterpreted and shouldRunScalaJsWasmCompiled.
  • wasm, runtime, compiler, wasi, compiler-tests, machine-tests and runtime-tests pass locally.
  • Building the example in a clean JDK 21 container gives a byte-identical .wasm.

@andreaTP
andreaTP merged commit 44cd9cf into bytecodealliance:main Nov 18, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant