Skip to content

Commit 11aaf06

Browse files
committed
Go: Handle Alias types by extracting the underlying types
1 parent 9a61d4e commit 11aaf06

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

go/extractor/extractor.go

+10
Original file line numberDiff line numberDiff line change
@@ -1507,9 +1507,18 @@ func extractSpec(tw *trap.Writer, spec ast.Spec, parent trap.Label, idx int) {
15071507
extractNodeLocation(tw, spec, lbl)
15081508
}
15091509

1510+
// If the given type is a type alias, this function resolves it to its underlying type.
1511+
func resolveTypeAlias(tp types.Type) types.Type {
1512+
if _, ok := tp.(*types.Alias); ok {
1513+
return tp.Underlying()
1514+
}
1515+
return tp
1516+
}
1517+
15101518
// extractType extracts type information for `tp` and returns its associated label;
15111519
// types are only extracted once, so the second time `extractType` is invoked it simply returns the label
15121520
func extractType(tw *trap.Writer, tp types.Type) trap.Label {
1521+
tp = resolveTypeAlias(tp)
15131522
lbl, exists := getTypeLabel(tw, tp)
15141523
if !exists {
15151524
var kind int
@@ -1666,6 +1675,7 @@ func extractType(tw *trap.Writer, tp types.Type) trap.Label {
16661675
// is constructed from their globally unique ID. This prevents cyclic type keys
16671676
// since type recursion in Go always goes through named types.
16681677
func getTypeLabel(tw *trap.Writer, tp types.Type) (trap.Label, bool) {
1678+
tp = resolveTypeAlias(tp)
16691679
lbl, exists := tw.Labeler.TypeLabels[tp]
16701680
if !exists {
16711681
switch tp := tp.(type) {

0 commit comments

Comments
 (0)