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/api_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/cmd/api/api_test.go') diff --git a/src/cmd/api/api_test.go b/src/cmd/api/api_test.go index 910e046f12..ba358d364d 100644 --- a/src/cmd/api/api_test.go +++ b/src/cmd/api/api_test.go @@ -285,6 +285,25 @@ func TestIssue41358(t *testing.T) { } } +func TestIssue64958(t *testing.T) { + defer func() { + if x := recover(); x != nil { + t.Errorf("expected no panic; recovered %v", x) + } + }() + + testenv.MustHaveGoBuild(t) + + for _, context := range contexts { + w := NewWalker(context, "testdata/src/issue64958") + pkg, err := w.importFrom("p", "", 0) + if err != nil { + t.Errorf("expected no error importing; got %T", err) + } + w.export(pkg) + } +} + func TestCheck(t *testing.T) { if !*flagCheck { t.Skip("-check not specified") -- cgit v1.3