Skip to content

Tracing static init fails on the Scala.js WebAssembly backend #4608

@fwbrasil

Description

@fwbrasil

Summary

I'm adding WASM support to Kyo and there's at least one blocker to support it in modules that integrate with cats-effect. On the Scala.js WebAssembly backend, constructing any IO throws java.lang.ClassCastException: undefined cannot be cast to java.lang.String. This blocks all cats-effect usage on the experimental Scala.js WASM backend.

Environment

  • cats-effect 3.6.1
  • Scala.js 1.21.0, ESModule output, experimentalUseWebAssembly = true
  • Scala 3.3.4
  • Node v23.2.0 (also reproduces on Node 22), flags --experimental-wasm-exnref --turboshaft-wasm
  • scala-cli 1.14.0 (drives the WASM build)

Reproduction

repro.scala:

//> using scala 3.3.4
//> using platform js
//> using jsVersion 1.21.0
//> using jsModuleKind es
//> using dep org.typelevel::cats-effect::3.6.1

import cats.effect.IO

@main def run(): Unit =
  println("before: constructing a cats-effect IO")
  try
    val io = IO.delay(())
    println("after: constructed " + io)
  catch
    case t: Throwable =>
      println("caught " + t.getClass.getName + ": " + t.getMessage)

WASM backend:

scala-cli --power package repro.scala --js-emit-wasm -o out --force
node --experimental-wasm-exnref --turboshaft-wasm ./out/main.js

JS backend, same source:

scala-cli run repro.scala

Observed

WASM:

before: constructing a cats-effect IO
caught org.scalajs.linker.runtime.UndefinedBehaviorError: java.lang.ClassCastException: undefined cannot be cast to java.lang.String

JS:

before: constructing a cats-effect IO
after: constructed IO(...)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions