From f1231a80d6974561571d172be0486cbfda952683 Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Mon, 26 Aug 2024 13:23:51 +0200 Subject: [PATCH] fix sizegen so it handles type aliases Signed-off-by: Andres Taylor --- go/tools/sizegen/sizegen.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/go/tools/sizegen/sizegen.go b/go/tools/sizegen/sizegen.go index a8fbcb1add4..7ecd50e3d8c 100644 --- a/go/tools/sizegen/sizegen.go +++ b/go/tools/sizegen/sizegen.go @@ -149,7 +149,7 @@ func (sizegen *sizegen) generateType(pkg *types.Package, file *codeFile, named * case *types.Interface: findImplementations(pkg.Scope(), tt, func(tt types.Type) { if _, isStruct := tt.Underlying().(*types.Struct); isStruct { - sizegen.generateKnownType(tt.(*types.Named)) + sizegen.generateTyp(tt) } }) default: @@ -157,6 +157,15 @@ func (sizegen *sizegen) generateType(pkg *types.Package, file *codeFile, named * } } +func (sizegen *sizegen) generateTyp(tt types.Type) { + switch tt := tt.(type) { + case *types.Named: + sizegen.generateKnownType(tt) + case *types.Alias: + sizegen.generateTyp(types.Unalias(tt)) + } +} + func (sizegen *sizegen) generateKnownType(named *types.Named) { pkgInfo := named.Obj().Pkg() file := sizegen.codegen[pkgInfo.Path()]