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

Async functions returning primitive values weirdly misbehave #178

Closed
kajacx opened this issue Feb 1, 2023 · 0 comments · Fixed by #189
Closed

Async functions returning primitive values weirdly misbehave #178

kajacx opened this issue Feb 1, 2023 · 0 comments · Fixed by #189

Comments

@kajacx
Copy link
Contributor

kajacx commented Feb 1, 2023

While working on this issue (#171), I discovered some wierd bugs with futures that have a primitive type as an output. I tried to re-trace my steps and add commits at logical point, see here: https://github.com/kajacx/fp-bindgen/commits/futures-primitive-return-types

The Setup

I added a build script for convenience, and then removed all the existing async stuff from the example, because it doesn't seem to work on Windows. that is the #171 bug, which is most likely unrelated to this issue.

First problem: Import/export async function returning a non-u64 primitive

If you declare any primitive other than u64 as the return type in either the import or export for an async function as the return type, the plugin will not build properly, saying that is is expecting u64 instead of the actual type. Full error message here: https://pastebin.com/15WPqtCw

Second problem: Export u64 async function gives a different error

On the other hand, exporting an async function that returns an u64 makes the runtime not compile. The error is about expecting u8 slice (or Vec) instead of u64. Again, full error here: https://pastebin.com/15WPqtCw

Third problem: You can return anything in async import function returning u64

If the protocol defines an async import function that should return a u64, you can actually return anything in the implementation in the runtime. Returning u64 (or u8/u16/u32 it seems) compiles and works as expected (can read correct value in wasm plugin), but returning anything else (other primitive or complex type) still compiles, but the test freezes at runtime. Tests that run before finish correctly.

Workaround

You can use a newtype as the return type to work around this, but of course it would be better to fix the issue.

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

Successfully merging a pull request may close this issue.

1 participant