Skip to content

generate outputting invalid go code #240

@MendyBerger

Description

@MendyBerger

wit-bindgen-go generate sometimes outputs invalid go code.
Seems to be happening with variants.

I have the following wit

package webidl:my-package;

world my-world {
    import my-interface: interface {
        variant my-variant {
            foo(my-resource),
        }
        resource my-resource {
            my-method: func(param: my-variant);
        }
    }
}

go run go.bytecodealliance.org/cmd/wit-bindgen-go generate -o internal/ wit

Outputs:
Error formatting file: error in abi.go: 13:34: expected type, found ')'

The actual api.go looks like:

// Code generated by wit-bindgen-go. DO NOT EDIT.

package myinterface

import (
	"go.bytecodealliance.org/cm"
)

func lower_MyVariant(v MyVariant) (f0 uint32, f1 uint32) {
f0 = (uint32)(v.Tag())
switch f0 {
case 0: // foo
v1 := cm.Reinterpret[uint32](*v.())
f1 = (uint32)(v1)
}
return
}

My understanding is the *v.() is the problem (I'm new to go)

Something weird I noticed: changing the namespace name from webidl to my-webidl resolves the problem with this specific wit, but not with other wit 🤷

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggoPull requests that update Go code

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions