WebAssembly if...else doc doesn't mention result statements which seem to be required if both branches have an explicit return #28013
Open
Description
MDN URL
https://developer.mozilla.org/en-US/docs/WebAssembly/Reference/Control_flow/if...else
What specific section or headline is this issue about?
No response
What information was incorrect, unhelpful, or incomplete?
In testing the if...else statement. Consider the following WAT:
(func $if_example (param $a i32) (param $b i32) (result i32)
local.get $a
local.get $b
i32.gt_s
(if
(then
local.get $a
return
)
(else
local.get $b
return
)
)
)
This will fail to compile. It appears that if you have an if/else combo, and both return, then you need a (result i32) inside the if block to appease the compiler. This seems to be because they have values on the stack, and otherwise the compiler expects no values on the stack. I feel like this optional, and sometimes necessary result statement should be mentioned on this page as it is a requirement to fix certain issues.
What did you expect to see?
Text mentioning that when you have values on the stack (including with return statements) in if branches, a result statement is required.
Do you have any supporting links, references, or citations?
No response
Do you have anything more you want to share?
No response
MDN metadata
Page report details
- Folder:
en-us/webassembly/reference/control_flow/if...else
- MDN URL: https://developer.mozilla.org/en-US/docs/WebAssembly/Reference/Control_flow/if...else
- GitHub URL: https://github.com/mdn/content/blob/main/files/en-us/webassembly/reference/control_flow/if...else/index.md
- Last commit: fe898dd
- Document last modified: 2023-02-23T10:05:41.000Z