Description
echo "`wit-bindgen-go version` | `tinygo version` | `wasmtime --version` | `uname -m`"
wit-bindgen-go version v0.5.0 | tinygo version 0.35.0 darwin/arm64 (using go version go1.23.4 and LLVM version 18.1.2) | wasmtime 28.0.1 (1bdf2c2b5 2025-01-14) | arm64
wit-bindgen-go represents the WIT definition type alias = result<bool, s8> with the following type definition: type Alias cm.Result[bool, bool, int8]. Initializing and retrieving a data value of type Alias produces unexpected behavior.
Component Model bindings are generated using wit-bindgen-go for the following WIT world definition:
world foo {
import wasi:io/streams@0.2.0;
import wasi:cli/stdout@0.2.0;
import wasi:random/random@0.2.0;
type alias = result<bool, s8>;
export wasi:cli/run@0.2.0;
}
The following Go source program targets the world foo. It initializes a variable of type Alias and writes its value to standard output:
func main() {
var val foo.Alias = cm.Err[foo.Alias](5)
if ok_val, err_val, is_err := val.Result(); is_err {
println("Err(", err_val, ")")
} else {
println("OK(", ok_val, ")")
}
}
When the program above is compiled to a Wasm component using tinygo and executed using Wasmtime, an incorrect value is printed.
Steps to reproduce
Here is a zipped directory that reproduces the bug:
wrong-result-value.zip
- Unzip
wrong-result-value.zip
- Build and run with
./verify.sh
Expected behavior
The printed value should be:
Actual behavior
I get the following output:
It seems that the Err value of type int8 is being treated as a bool i.e. odd numbered values result in 1 being printed while even values result in 0. The correct value is printed if the shape of the result is changed to int8.
Additional context
The Go source program was derived from programs generated by a differential testing framework for wit-bindgen. The wit definitions are derived from a test case produced by wit-smith.
Description
wit-bindgen-gorepresents the WIT definitiontype alias = result<bool, s8>with the following type definition:type Alias cm.Result[bool, bool, int8]. Initializing and retrieving a data value of typeAliasproduces unexpected behavior.Component Model bindings are generated using
wit-bindgen-gofor the following WIT world definition:The following Go source program targets the world
foo. It initializes a variable of typeAliasand writes its value to standard output:When the program above is compiled to a Wasm component using tinygo and executed using Wasmtime, an incorrect value is printed.
Steps to reproduce
Here is a zipped directory that reproduces the bug:
wrong-result-value.zip
wrong-result-value.zip./verify.shExpected behavior
The printed value should be:
Actual behavior
I get the following output:
It seems that the Err value of type
int8is being treated as abooli.e. odd numbered values result in 1 being printed while even values result in 0. The correct value is printed if the shape of the result is changed toint8.Additional context
The Go source program was derived from programs generated by a differential testing framework for wit-bindgen. The wit definitions are derived from a test case produced by wit-smith.