wasm_component_layer
wasm_component_layer copied to clipboard
`option` + number bugs
Hi, I've probably found a bug.
When option<a_number>
is a function parameter type then Func::call
often panics or the function body is not called at all. It doesn't matter whether the parameter is option
or the parameter is a record
containing the option
.
I've made a runnable example in my fork, see the component's lib.rs:
impl exports::test::guest::foo::Guest for Foo {
fn fn_calling_host_fn() {
// 1)
// Works as expected - prints `A message from host.`
// WIT: `host-fn: func(param: option<s32>);`
// Params: `[ValueType::Option(OptionType::new(ValueType::S32))]`
test::guest::host::host_fn(None);
// 2)
// Panics with the error `Invalid discriminant value.`
// WIT: `host-fn: func(param: option<s32>);`
// Params: `[ValueType::Option(OptionType::new(ValueType::S32))]`
// test::guest::host::host_fn(Some(123));
// 3)
// Panics with the error `Incorrect type. src\func.rs:816:27` (see updated `require_matches` below)
// WIT: `host-fn: func(param: option<f64>);`
// Params: `[ValueType::Option(OptionType::new(ValueType::F64))]`
// test::guest::host::host_fn(None);
}
}
Also it may behave differently on each runtime. For example, in my project, a function like host-fn: func(param: option<f64>) -> result;
returns immediately Ok
without running the Func
body at all on the js_wasm_runtime_layer
runtime and it works correctly when I change param: option<f64>
to option<string>
or option<s32>
.
I've tried to upgrade wit-bindgen = "0.16.0"
to "0.26.0"
but it doesn't affect the issue.
Context: I was writing an example with wasm_component_layer
in MoonZoon and then I would like to use it in another OS project with Tauri where I want to use both js_wasm_runtime_layer
and wasmtime_runtime_layer
. These bugs and missing bindgen are stoppers for me, unfortunately.
Hope it helps, ask me any questions.