circuitgen icon indicating copy to clipboard operation
circuitgen copied to clipboard

Generation failure on go 1.23 with type aliases

Open deefdragon opened this issue 1 year ago • 2 comments

When using go toolchain 1.23.0 and go version 1.23, interfaces with methods that has an aliased type as an argument will fail to generate with the following error

[debug] loadPackages took 32.180249ms
[debug] resolvePackagePath took 11.411105ms
Error: generating circuit wrapper: resolvePkgPaths: invalid type: <module>/api.TestAlias

(The file was not in the module root, but in the /api folder, so I would have expected the path to be <module>/api/api.TestAlias)

This is the smallest example I could create, and produced the above error.

package api

import (
	"context"
)

type TestInterface interface {
	SomeFunc(ctx context.Context, body TestAlias) (*int, error)
}

type TestAlias = TestBase

type TestBase struct {
	Foo int
}

Command used to generate: go run github.com/twitchtv/circuitgen --name TestInterface --pkg ./ --debug --out ./circuit.gen.go --alias TestCircuit --circuit-major-version 3

deefdragon avatar Aug 17 '24 06:08 deefdragon

This is a consiquence of the go 1.23 change to go/types

By default, go/types now produces Alias type nodes for type aliases

I was able to resolve this by adding case *types.Alias: to resolvePkgPaths' breakout cases locally. It should also be temporarily resolvable by setting GODEBUG=gotypesalias=0

deefdragon avatar Aug 17 '24 07:08 deefdragon

~~I attempted to do the quick fix I mentioned, but testing was not running due to errorcheck panic-ing. Even bypassing it, I was running into other issues getting the generation to properly execute. I think there are deeper issues around the more modern versions of go.~~

update: I believe that this was due to how I have my go environment set up. Adding the types.Alias case should work fine.

deefdragon avatar Sep 13 '24 04:09 deefdragon