Skip to content

wit/bindgen: inconsistent generated Go names for variant cases that collide with other names #215

@rvolosatovs

Description

@rvolosatovs

For WIT:

package test:repro;

interface repro {
    variant var {
        var(u8),
    }

    foo: func(var: var);
}

world imports {
    import repro;
}

wasm-tools-go 0.3.0 generates inconsistent Var accessors.

In abi.go:

func lower_Var(v Var) (f0 uint32, f1 uint32) {
	f0 = (uint32)(v.Tag())
	switch f0 {
	case 0: // var
		v1 := (uint32)(*v.Var())
		f1 = (uint32)(v1)
	}
	return
}

In repro.wit.go:

// Var_ returns a non-nil *[uint8] if [Var] represents the variant case "var".
func (self *Var) Var_() *uint8 {
	return cm.Case[uint8](self, 0)
}

See https://github.com/rvolosatovs/wasm-tools-go-var-gen-repro for a full example

Update: naming the variant some other name, matching an identifier used in the interface causes the same issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions