From bbe24060f9d3d7cd4e76f62b8d77871afda996d0 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Fri, 16 Aug 2024 10:51:47 +0100 Subject: [PATCH] Go: Extract type aliases --- go/extractor/extractor.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/go/extractor/extractor.go b/go/extractor/extractor.go index 4926d8e3e13..84ccc58a5ca 100644 --- a/go/extractor/extractor.go +++ b/go/extractor/extractor.go @@ -1647,6 +1647,9 @@ func extractType(tw *trap.Writer, tp types.Type) trap.Label { } extractComponentType(tw, lbl, i, tildeStr, term.Type()) } + case *types.Alias: + kind = dbscheme.TypeAlias.Index() + dbscheme.AliasRhsTable.Emit(tw, lbl, extractType(tw, tp.Rhs())) default: log.Fatalf("unexpected type %T", tp) } @@ -1790,6 +1793,14 @@ func getTypeLabel(tw *trap.Writer, tp types.Type) (trap.Label, bool) { fmt.Fprintf(&b, "{%s}", compLbl) } lbl = tw.Labeler.GlobalID(fmt.Sprintf("%s;typesetliteraltype", b.String())) + case *types.Alias: + var b strings.Builder + b.WriteString(tp.Obj().Id()) + // Ensure that the definition of the alias gets extracted, + // which may be an alias in itself. + extractType(tw, tp.Rhs()) + // Construct the label for this type alias. + lbl = tw.Labeler.GlobalID(fmt.Sprintf("%s;typealias", b.String())) default: log.Fatalf("(getTypeLabel) unexpected type %T", tp) }