Skip to content

Corrupted value of type result<u64, tuple<option<u64>>> #344

@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 type alias = result<u64, tuple<option<u64>>> with the following type definition: type Alias cm.Result[[1]cm.Option[uint64], uint64, [1]cm.Option[uint64]]. Initializing and retrieving a data value of type Alias produces an incorrect value.

Component model bindings are generated for the following WIT world:

world foo {
 ... wasi imports ...

  type alias = result<u64, tuple<option<u64>>>;
  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() {
	passed := uint64(2)
	var alias foo.Alias = foo.Alias(cm.OK[cm.Result[[1]cm.Option[uint64], uint64, [1]cm.Option[uint64]]](passed))
	received := *alias.OK()

	println("passed:", passed)
	println("received:", received)
}

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-corrupted-result-tuple-option
  3. Build and run with ./verify.sh

Expected behavior

The printed values should be the same:

passed: 2
received: 2

Actual behavior

I get the following output:

passed: 2
received: 0

Additional context

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions