From 15dcdeb5aacb4503e3d053f198bd4669d5cec2aa Mon Sep 17 00:00:00 2001 From: "Devon H. O'Dell" Date: Thu, 4 Jan 2024 11:49:17 -0500 Subject: cmd/api: fix panic on exported basic type aliases The order of emitting named type and type aliases in the `Walker`'s `emitType` function is inverted. When the type alias references a basic type, this causes a panic as the type assertion on `*types.Named` fails. This change reorders the logic such that type aliases are emitted prior to this type assertion. Fixes #64958 Change-Id: I52dbe13999978912ded788d9cf4948103869bcfa Reviewed-on: https://go-review.googlesource.com/c/go/+/554076 Reviewed-by: Bryan Mills LUCI-TryBot-Result: Go LUCI Auto-Submit: Bryan Mills --- src/cmd/api/main_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/cmd/api/main_test.go') diff --git a/src/cmd/api/main_test.go b/src/cmd/api/main_test.go index 94e159e7d8..7985055b5c 100644 --- a/src/cmd/api/main_test.go +++ b/src/cmd/api/main_test.go @@ -957,17 +957,17 @@ func (w *Walker) emitType(obj *types.TypeName) { if w.isDeprecated(obj) { w.emitf("type %s //deprecated", name) } + typ := obj.Type() + if obj.IsAlias() { + w.emitf("type %s = %s", name, w.typeString(typ)) + return + } if tparams := obj.Type().(*types.Named).TypeParams(); tparams != nil { var buf bytes.Buffer buf.WriteString(name) w.writeTypeParams(&buf, tparams, true) name = buf.String() } - typ := obj.Type() - if obj.IsAlias() { - w.emitf("type %s = %s", name, w.typeString(typ)) - return - } switch typ := typ.Underlying().(type) { case *types.Struct: w.emitStructType(name, typ) -- cgit v1.3-5-g9baa