Skip to content

Commit 1c171a4

Browse files
committed
Extract entities for type parameters
This was overlooked previously. We already do this for named types. I have confirmed that none of the other cases in this switch statement are entities, that is they don't have a field of type `object` that can be accessed using `Obj()`.
1 parent 6713436 commit 1c171a4

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

go/extractor/extractor.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,15 +1584,7 @@ func extractType(tw *trap.Writer, tp types.Type) trap.Label {
15841584
extractUnderlyingType(tw, lbl, underlying)
15851585
trackInstantiatedStructFields(tw, tp, origintp)
15861586

1587-
entitylbl, exists := tw.Labeler.LookupObjectID(origintp.Obj(), lbl)
1588-
if entitylbl == trap.InvalidLabel {
1589-
log.Printf("Omitting type-object binding for unknown object %v.\n", origintp.Obj())
1590-
} else {
1591-
if !exists {
1592-
extractObject(tw, origintp.Obj(), entitylbl)
1593-
}
1594-
dbscheme.TypeObjectTable.Emit(tw, lbl, entitylbl)
1595-
}
1587+
extractTypeObject(tw, lbl, origintp.Obj())
15961588

15971589
// ensure all methods have labels - note that methods do not have a
15981590
// parent scope, so they are not dealt with by `extractScopes`
@@ -1614,6 +1606,8 @@ func extractType(tw *trap.Writer, tp types.Type) trap.Label {
16141606
parentlbl := getTypeParamParentLabel(tw, tp)
16151607
constraintLabel := extractType(tw, tp.Constraint())
16161608
dbscheme.TypeParamTable.Emit(tw, lbl, tp.Obj().Name(), constraintLabel, parentlbl, tp.Index())
1609+
1610+
extractTypeObject(tw, lbl, tp.Obj())
16171611
case *types.Union:
16181612
kind = dbscheme.TypeSetLiteral.Index()
16191613
for i := 0; i < tp.Len(); i++ {
@@ -1775,6 +1769,19 @@ func getTypeLabel(tw *trap.Writer, tp types.Type) (trap.Label, bool) {
17751769
return lbl, exists
17761770
}
17771771

1772+
// extractTypeObject extracts a single type object and emits it to the type object table.
1773+
func extractTypeObject(tw *trap.Writer, lbl trap.Label, entity *types.TypeName) {
1774+
entitylbl, exists := tw.Labeler.LookupObjectID(entity, lbl)
1775+
if entitylbl == trap.InvalidLabel {
1776+
log.Printf("Omitting type-object binding for unknown object %v.\n", entity)
1777+
} else {
1778+
if !exists {
1779+
extractObject(tw, entity, entitylbl)
1780+
}
1781+
dbscheme.TypeObjectTable.Emit(tw, lbl, entitylbl)
1782+
}
1783+
}
1784+
17781785
// extractKeyType extracts `key` as the key type of the map type `mp`
17791786
func extractKeyType(tw *trap.Writer, mp trap.Label, key types.Type) {
17801787
dbscheme.KeyTypeTable.Emit(tw, mp, extractType(tw, key))

0 commit comments

Comments
 (0)