moonbit-docs icon indicating copy to clipboard operation
moonbit-docs copied to clipboard

Public function returns a ghost i32

Open fantix opened this issue 1 year ago • 1 comments

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 🤔

fantix avatar Feb 05 '24 01:02 fantix

Private functions also return i32, but it's less of an issue because they are not publicly visible on WASM level.

fantix avatar Feb 05 '24 01:02 fantix

This is fixed in today's release.

peter-jerry-ye avatar Jun 25 '24 09:06 peter-jerry-ye