Skip to content

Commit a857069

Browse files
authored
Merge pull request #19464 from owen-mc/go/fix/extract-recv-alias-type
Go: fix database inconsistency when receiver has alias type
2 parents 55efb11 + c781f98 commit a857069

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

go/extractor/extractor.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,18 +1582,10 @@ func isAlias(tp types.Type) bool {
15821582
return ok
15831583
}
15841584

1585-
// If the given type is a type alias, this function resolves it to its underlying type.
1586-
func resolveTypeAlias(tp types.Type) types.Type {
1587-
if isAlias(tp) {
1588-
return types.Unalias(tp) // tp.Underlying()
1589-
}
1590-
return tp
1591-
}
1592-
15931585
// extractType extracts type information for `tp` and returns its associated label;
15941586
// types are only extracted once, so the second time `extractType` is invoked it simply returns the label
15951587
func extractType(tw *trap.Writer, tp types.Type) trap.Label {
1596-
tp = resolveTypeAlias(tp)
1588+
tp = types.Unalias(tp)
15971589
lbl, exists := getTypeLabel(tw, tp)
15981590
if !exists {
15991591
var kind int
@@ -1771,7 +1763,7 @@ func extractType(tw *trap.Writer, tp types.Type) trap.Label {
17711763
// is constructed from their globally unique ID. This prevents cyclic type keys
17721764
// since type recursion in Go always goes through defined types.
17731765
func getTypeLabel(tw *trap.Writer, tp types.Type) (trap.Label, bool) {
1774-
tp = resolveTypeAlias(tp)
1766+
tp = types.Unalias(tp)
17751767
lbl, exists := tw.Labeler.TypeLabels[tp]
17761768
if !exists {
17771769
switch tp := tp.(type) {

go/extractor/trap/labels.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,12 @@ func (l *Labeler) ScopedObjectID(object types.Object, getTypeLabel func() Label)
169169

170170
// findMethodWithGivenReceiver finds a method with `object` as its receiver, if one exists
171171
func findMethodWithGivenReceiver(object types.Object) *types.Func {
172-
meth := findMethodOnTypeWithGivenReceiver(object.Type(), object)
172+
unaliasedType := types.Unalias(object.Type())
173+
meth := findMethodOnTypeWithGivenReceiver(unaliasedType, object)
173174
if meth != nil {
174175
return meth
175176
}
176-
if pointerType, ok := object.Type().(*types.Pointer); ok {
177+
if pointerType, ok := unaliasedType.(*types.Pointer); ok {
177178
meth = findMethodOnTypeWithGivenReceiver(pointerType.Elem(), object)
178179
}
179180
return meth

0 commit comments

Comments
 (0)