cmd/cloner, cmd/viewer, util/codegen: add support for aliases of cloneable types
We have several checked type assertions to *types.Named in both cmd/cloner and cmd/viewer. As Go 1.23 updates the go/types package to produce Alias type nodes for type aliases, these type assertions no longer work as expected unless the new behavior is disabled with gotypesalias=0. In this PR, we add codegen.NamedTypeOf(t types.Type), which functions like t.(*types.Named) but also unrolls type aliases. We then use it in place of type assertions in the cmd/cloner and cmd/viewer packages where appropriate. We also update type switches to include *types.Alias alongside *types.Named in relevant cases, remove *types.Struct cases when switching on types.Type.Underlying and update the tests with more cases where type aliases can be used. Updates #13224 Updates #12912 Signed-off-by: Nick Khyl <nickk@tailscale.com>
This commit is contained in:
@@ -204,13 +204,27 @@ type StructWithContainers struct {
|
||||
}
|
||||
|
||||
type (
|
||||
StructWithPtrsAlias = StructWithPtrs
|
||||
StructWithoutPtrsAlias = StructWithoutPtrs
|
||||
StructWithPtrsAlias = StructWithPtrs
|
||||
StructWithoutPtrsAlias = StructWithoutPtrs
|
||||
StructWithPtrsAliasView = StructWithPtrsView
|
||||
StructWithoutPtrsAliasView = StructWithoutPtrsView
|
||||
)
|
||||
|
||||
type StructWithTypeAliasFields struct {
|
||||
WithPtr StructWithPtrsAlias
|
||||
WithoutPtr StructWithoutPtrsAlias
|
||||
|
||||
WithPtrByPtr *StructWithPtrsAlias
|
||||
WithoutPtrByPtr *StructWithoutPtrsAlias
|
||||
|
||||
SliceWithPtrs []*StructWithPtrsAlias
|
||||
SliceWithoutPtrs []*StructWithoutPtrsAlias
|
||||
|
||||
MapWithPtrs map[string]*StructWithPtrsAlias
|
||||
MapWithoutPtrs map[string]*StructWithoutPtrsAlias
|
||||
|
||||
MapOfSlicesWithPtrs map[string][]*StructWithPtrsAlias
|
||||
MapOfSlicesWithoutPtrs map[string][]*StructWithoutPtrsAlias
|
||||
}
|
||||
|
||||
type integer = constraints.Integer
|
||||
|
||||
Reference in New Issue
Block a user