Closed ukyo closed 7 years ago
A function that returns a value in block throws an error as below.
export function foo(x: int32): int32 { { return 100; } }
fetch("foo.wasm") .then(res => res.arrayBuffer()) .then(buff => WebAssembly.instantiate(buff)) .then(({module, instance}) => { console.log(instance.exports.foo(1)); });
(index):8 Uncaught (in promise) CompileError: Compiling WASM function #0:<?> failed:Result = expected 1 elements on the stack for fallthru to @1 @+8
wast code(generated with wasm2wast)
(module (type (;0;) (func (result i32))) (func (;0;) (type 0) (result i32) block ;; label = @1 i32.const 100 return end) (memory (;0;) 1) (export "memory" (memory 0)) (export "foo" (func 0)) (data (i32.const 8) "\db\0fI@(\00\00\00(\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"))
Its a known bug. A block should define a return type if something returned inside a block.
A function that returns a value in block throws an error as below.
wast code(generated with wasm2wast)