Skip to content

Corrupted value of type result<tuple<tuple<u8, s32>>, s32> #352

@ethanstanley3

Description

@ethanstanley3

Description

echo "`wit-bindgen-go version` | `tinygo version` | `wasmtime --version` | `uname -m`"
wit-bindgen-go version v0.6.2 | tinygo version 0.37.0 darwin/arm64 (using go version go1.24.3 and LLVM version 19.1.2) | wasmtime 32.0.0 (d3054950c 2025-04-21) | arm64

wit-bindgen-go represents the WIT definition result<tuple<tuple<u8, s32>>, s32> with the following type definition: cm.Result[[1]cm.Tuple[uint8, int32], [1]cm.Tuple[uint8, int32], int32]. Initializing and retrieving a data value of this type produces an incorrect value.

Note: similar to #344, it seems that the result shape is causing the high 24 bits of the result's error case to be ignored. However, the fix in #349 does not prevent the unexpected behavior seen in this test case.

Component model bindings are generated for the following WIT world:

world foo {
 ... wasi imports ...

  type alias = result<tuple<tuple<u8, s32>>, s32>;
  export wasi:cli/run@0.2.0;
}

The following Go program implements foo. It initializes a value of type Alias and prints its value.

func main() {
	want := int32(-1)
	var alias foo.Alias = cm.Err[foo.Alias](want)
	got := *alias.Err()

	println("want:", want)
	println("got:", got)
}

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: test-case.zip

  1. Unzip test-case.zip
  2. cd go-result-tuple-tuple-corruption
  3. Build and run with ./verify.sh

Expected behavior

The printed values should be the same:

want: -1
got: -1

Actual behavior

The values differ:

want: -1
got: 255

Additional context

The Go source program was derived from programs generated by a differential testing framework for WIT binding generators. The WIT definition was derived from a test case produced by wit-smith.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions