Skip to content

Commit

Permalink
issue #298 - go 1.23 go/types alias change
Browse files Browse the repository at this point in the history
  • Loading branch information
xanderflood committed Oct 9, 2024
1 parent 224623a commit ac22042
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
23 changes: 16 additions & 7 deletions generator/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,10 @@ func (f *Fake) addImportsFor(typ types.Type) {
f.addImportsFor(t.Elem())
case *types.Chan:
f.addImportsFor(t.Elem())
case *types.Alias:
f.addImportsForNamedType(t)
case *types.Named:
if t.Obj() != nil && t.Obj().Pkg() != nil {
typeArgs := t.TypeArgs()
for i := 0; i < typeArgs.Len(); i++ {
f.addImportsFor(typeArgs.At(i))
}
f.Imports.Add(t.Obj().Pkg().Name(), t.Obj().Pkg().Path())
}
f.addImportsForNamedType(t)
case *types.Slice:
f.addImportsFor(t.Elem())
case *types.Array:
Expand All @@ -154,3 +150,16 @@ func (f *Fake) addImportsFor(typ types.Type) {
log.Printf("!!! WARNING: Missing case for type %s\n", reflect.TypeOf(typ).String())
}
}

func (f *Fake) addImportsForNamedType(t interface {
Obj() *types.TypeName
TypeArgs() *types.TypeList
}) {
if t.Obj() != nil && t.Obj().Pkg() != nil {
typeArgs := t.TypeArgs()
for i := 0; i < typeArgs.Len(); i++ {
f.addImportsFor(typeArgs.At(i))
}
f.Imports.Add(t.Obj().Pkg().Name(), t.Obj().Pkg().Path())
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

go 1.22.0
go 1.23

toolchain go1.23.1

0 comments on commit ac22042

Please sign in to comment.