moonbit-docs
moonbit-docs copied to clipboard
Public function returns a ghost i32
Public functions without returning types are currently compiled into WASM functions that return i32s:
pub fn no_return(a: Int, b: Int) {
let _ = a + b
}
pub fn no_args_no_return() {
no_return(2, 3)
}
pub fn empty_func() {
}
compiles to:
(func $$username/hello/main.no_return.fn/1
(export "username/hello/main::no_return")
(param $a/1 i32) (param $b/2 i32) (result i32)
(local.get $a/1) (local.get $b/2) (i32.add) (drop)
(i32.const 0))
(func $$username/hello/main.no_args_no_return.fn/2
(export "username/hello/main::no_args_no_return") (result i32)
(i32.const 2) (i32.const 3) (call $$username/hello/main.no_return.fn/1))
(func $$username/hello/main.empty_func.fn/3
(export "username/hello/main::empty_func") (result i32) (i32.const 0))
which doesn't really make sense 🤔
Private functions also return i32, but it's less of an issue because they are not publicly visible on WASM level.
This is fixed in today's release.