Skip to content

Commit

Permalink
Merge pull request #267 from bytecodealliance/ydnar/issue-264
Browse files Browse the repository at this point in the history
wit/bindgen: correctly cast to named Go bool types when lowering
  • Loading branch information
ydnar authored Dec 11, 2024
2 parents 350ed0e + e97bebe commit 4404cd2
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- [#264](https://github.com/bytecodealliance/go-modules/issues/264): fix lowering for imported functions that return named `bool` types.

## [v0.4.1] — 2024-12-09

### Added
Expand Down
10 changes: 10 additions & 0 deletions testdata/issues/issue264.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package issues:issue264;

interface i {
type boolean = bool;
f: func() -> boolean;
}

world w {
import i;
}
59 changes: 59 additions & 0 deletions testdata/issues/issue264.wit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"worlds": [
{
"name": "w",
"imports": {
"interface-0": {
"interface": {
"id": 0
}
}
},
"exports": {},
"package": 0
}
],
"interfaces": [
{
"name": "i",
"types": {
"boolean": 0
},
"functions": {
"f": {
"name": "f",
"kind": "freestanding",
"params": [],
"results": [
{
"type": 0
}
]
}
},
"package": 0
}
],
"types": [
{
"name": "boolean",
"kind": {
"type": "bool"
},
"owner": {
"interface": 0
}
}
],
"packages": [
{
"name": "issues:issue264",
"interfaces": {
"i": 0
},
"worlds": {
"w": 0
}
}
]
}
10 changes: 10 additions & 0 deletions testdata/issues/issue264.wit.json.golden.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package issues:issue264;

interface i {
type boolean = bool;
f: func() -> boolean;
}

world w {
import i;
}
2 changes: 1 addition & 1 deletion tests/generated/wasi/cli/v0.2.0/exit/exit.wit.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/generated/wasi/cli/v0.2.0/run/run.wasm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/generated/wasi/filesystem/v0.2.0/types/types.wit.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/generated/wasi/io/v0.2.0/poll/poll.wit.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/generated/wasi/sockets/v0.2.0/tcp/tcp.wit.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wit/bindgen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,7 @@ func (g *generator) cast(file *gen.File, dir wit.Direction, from, to wit.Type, i
if t != nil {
return g.cmCall(file, goKind(from)+"To"+goKind(to)+"["+g.typeRep(file, dir, t)+"]", input)
}
return g.cmCall(file, goKind(from)+"To"+goKind(to), input)
return "(" + g.typeRep(file, dir, to) + ")(" + g.cmCall(file, goKind(from)+"To"+goKind(to), input) + ")"
}

func goKind(t wit.Node) string {
Expand Down

0 comments on commit 4404cd2

Please sign in to comment.