Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

option + number bugs #17

Open
MartinKavik opened this issue Jun 23, 2024 · 1 comment
Open

option + number bugs #17

MartinKavik opened this issue Jun 23, 2024 · 1 comment

Comments

@MartinKavik
Copy link

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.

@Clunt
Copy link
Contributor

Clunt commented Jul 10, 2024

I don't know if this PR(#19) has anything to do with your problem.
If you have time, you can run the example and have a look. (README.md example part, run value_none example)
Feel free to contact me if you have any further questions, I am trying to implement WASIp2 with this repo.

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

No branches or pull requests

2 participants