Skip to content

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

Closed

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(...)

Activity

  1. durban commented on Jun 5, 2026

    @durban
    Contributor

    The issue title mentions tracing, but then the description doesn't. Is there any indication this is a tracing issue? E.g., does it work with tracing turned off?

  2. djspiewak commented on Jun 21, 2026

    @djspiewak
    Member

    @fwbrasil Quick warning: as a policy, we do not allow LLM generated issues, comments, or PR descriptions on any Typelevel repository. You may not be aware of this, and this does look like a legitimate bug to me, so I'm going to leave it alone this time.

    In the future, please do not have claude open issues on your behalf. We accept generated code, but not prose.

  3. djspiewak commented on Jun 21, 2026

    @djspiewak
    Member

    For folks following breadcrumbs… here's a minimizer which doesn't involve Cats Effect:

    //> using scala 3.3.4
    //> using platform js
    //> using jsVersion 1.21.0
    //> using jsModuleKind es
    
    import scala.scalajs.js
    
    @main def run(): Unit =
      val names = js.Object.getOwnPropertyNames((() => ()).asInstanceOf[js.Object])
      val dyn = names.asInstanceOf[js.Dynamic]
    
      println(s"own property count = ${names.length}")
      println(s"own properties = ${js.JSON.stringify(names)}")
      println(s"typeof names(0) = ${js.typeOf(dyn.selectDynamic("0"))}")
    
      try
        val propertyName: String = names(0)
        println(s"first own property = $propertyName")
      catch
        case t: Throwable =>
          println(s"caught ${t.getClass.getName}: ${t.getMessage}")
          println(s"cause = ${t.getCause}")

    Tldr the value of getOwnPropertyNames for Function0 differs between default scala-js and wasm.

  4. fwbrasil commented on Jul 18, 2026

    @fwbrasil
    Author

    @fwbrasil Quick warning: as a policy, we do not allow LLM generated issues, comments, or PR descriptions on any Typelevel repository. You may not be aware of this, and this does look like a legitimate bug to me, so I'm going to leave it alone this time.

    Lol good luck then! I for sure won't collaborate with a project with such dated policy and arbitrary inferences about people's contributions. It'd be much more valuable to critique the content than the form, and this is a validated issue indeed blocking use of cats-effect with wasm.

    I wonder if this could end up becoming a blocker to keep integrations with Typelevel projects in Kyo but let's see how it goes. At least this time I wasn't offended as "sewage" for correctly reporting an issue like in the past so it's some progress 😉

  5. fwbrasil commented on Jul 24, 2026

    @fwbrasil
    Author

    Just to document since my comment on typelevel/tsc#194 got deleted. I hadn't noticed that there was a previous attempt at adding wasm support that got blocked exactly on the issue I reported here. It demonstrates the accuracy of the report despite @djspiewak's bogus accusation with a made up org-wide AI policy: #4308 (comment) #4386 (comment)

  6. djspiewak commented on Jul 24, 2026

    @djspiewak
    Member

    My allusion to an org wide policy was erroneous, yes. We had been having internal discussions about such a thing for a while and I forgot that we hadn't proceeded publicly yet. Regardless of any org wide policy though, I as a project owner will moderate the communications on the projects I steward in a manner I believe to be in the best interest of myself and the community. That was why I chose to leave this issue open despite believing what I said about an AI policy: it's a valid issue and I appreciate that you found and filed it!

    We do have an org wide policy about civility though, and I am gently warning you that you are stepping over that line right now. Do not pick fights, and do not circumvent moderation. I'm choosing to leave this comment up, but if it happens again I will take action rather than issuing further warnings.

  7. deleted a comment from fwbrasil on Jul 24, 2026
  8. samspills commented on Jul 24, 2026

    @samspills
    Contributor

    Hi just an FYI that as a CE maintainer I've deleted a comment and taken the liberty, afforded to me by being a maintainer, of banning the user after multiple warnings about how they engage with the community.

    Stay purrin' friends <3

  9. kubukoz commented on Jul 24, 2026

    @kubukoz
    Member

    What's the purpose of deleting such a comment? I feel like for the sake of transparency, it would be in the community's best interest to be able to see what the user was banned for...

  10. djspiewak commented on Jul 24, 2026

    @djspiewak
    Member

    Fair point and acknowledged. Let's move this discussion to the appropriate channel in discord though rather than taking this issue further off topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions