Adding Wasm targets to Kotest, I'm seeing a `Compi...
# webassembly
o
Adding Wasm targets to Kotest, I'm seeing a `CompileError: WebAssembly.Module()`:
Copy code
local.get of type externref has to be in the same reference type hierarchy as (ref 2204) @+1331845
If my code is at fault, wouldn't the Kotlin compiler be supposed to report an error? Details in 🧵.
Full error message:
Copy code
file:.../kotest/kotest-framework/kotest-framework-multiplatform-plugin-gradle/test-project/build/js/packages/test-project-wasm-js-test/kotlin/test-project-wasm-js-test.uninstantiated.mjs:3890
        const wasmModule = new WebAssembly.Module(wasmBuffer);
                           ^
CompileError: WebAssembly.Module(): Compiling function #15410:"io.kotest.common.runPromise$lambda.invoke" failed: Invalid types for ref.test: local.get of type externref has to be in the same reference type hierarchy as (ref 2204) @+1331845
    at instantiate (file:.../kotest/kotest-framework/kotest-framework-multiplatform-plugin-gradle/test-project/build/js/packages/test-project-wasm-js-test/kotlin/test-project-wasm-js-test.uninstantiated.mjs:3890:28)
    at async file:.../kotest/kotest-framework/kotest-framework-multiplatform-plugin-gradle/test-project/build/js/packages/test-project-wasm-js-test/kotlin/test-project-wasm-js-test.mjs:3:17
Node.js v22.0.0-v8-canary20231213fc7703246e
s
Yes, faults in your code should not cause Wasm CompileError. It looks like a bug down the line in Kotlin compiler or Node.
o
OK, I'll file an issue then with a link to the corresponding repo branch.
s
Greatly appreciated. Thanks!
👍 1
👍🏾 1
o
Since there is also a compiler plugin involved which operates on the backend IR level, I hope that the above is not influenced by that. I haven't yet looked very closely at possible compiler plugin differences between JS and Wasm targets in this case.
Here we go: KT-64357, and the error reproduces without using the compiler plugin.
🙏 1
In K/Wasm,
Promise.catch(onRejected: (JsAny) -> S)
invokes its lambda with a
JsAny
parameter instead of a
Throwable
as in K/JS. The Wasm CompileError seems to be caused by casting that
JsAny
to
Throwable
, which is required for re-throwing. Added a simple reproducer to KT-64357. If you have a good idea for a workaround, please let me know so that folks can get a Kotest version with a Wasm target without waiting for compiler fixes.
🙏 1