Skip to content

Commit 09da46d

Browse files
committed
Go: Address review comments
1 parent e0f0987 commit 09da46d

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

go/extractor/extractor.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,11 +2010,9 @@ func extractTypeParamDecls(tw *trap.Writer, fields *ast.FieldList, parent trap.L
20102010
}
20112011

20122012
func populateTypeParamParentsFromFunction(funcObj *types.Func) {
2013-
recvTypeParams := funcObj.Type().(*types.Signature).RecvTypeParams()
2014-
populateTypeParamParents(recvTypeParams, funcObj, true)
2015-
typeParams := funcObj.Type().(*types.Signature).TypeParams()
2016-
populateTypeParamParents(typeParams, funcObj, false)
2017-
2013+
signature := funcObj.Type().(*types.Signature)
2014+
populateTypeParamParents(signature.RecvTypeParams(), funcObj, true)
2015+
populateTypeParamParents(signature.TypeParams(), funcObj, false)
20182016
}
20192017

20202018
// populateTypeParamParents sets `parent` as the parent of the elements of `typeparams`
@@ -2053,12 +2051,14 @@ func getTypeParamParentLabel(tw *trap.Writer, tp *types.TypeParam) (trap.Label,
20532051
return parentlbl, entry.isFromReceiver
20542052
}
20552053

2056-
func setTypeParamParent(tp *types.TypeParam, newobj types.Object, isFromReceiver bool) {
2054+
func setTypeParamParent(tp *types.TypeParam, parent types.Object, isFromReceiver bool) {
20572055
entry, exists := typeParamParent[tp]
2056+
newEntry := typeParamParentEntry{parent, isFromReceiver}
20582057
if !exists {
2059-
typeParamParent[tp] = typeParamParentEntry{newobj, isFromReceiver}
2060-
} else if entry.parent != newobj {
2061-
log.Fatalf("Parent of type parameter '%s %s' being set to a different value: '%s' vs '%s'", tp.String(), tp.Constraint().String(), entry.parent, newobj)
2058+
typeParamParent[tp] = newEntry
2059+
} else if entry != newEntry {
2060+
log.Fatalf("Parent of type parameter '%s %s' being set to a different value: {'%s', %t}' vs {'%s', %t}",
2061+
tp.String(), tp.Constraint().String(), entry.parent, entry.isFromReceiver, parent, isFromReceiver)
20622062
}
20632063
}
20642064

go/ql/lib/upgrades/b1341734d6870b105e5c9d168ce7dec25d7f72d0/typeparam.ql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ class TypeParamParentObject extends @typeparamparentobject {
1010
string toString() { none() }
1111
}
1212

13+
// In Go 1.26 and below, a type parameter is from a receiver exactly when its
14+
// parent is a method.
15+
boolean isFromReceiver(TypeParamParentObject parent) {
16+
if methodreceivers(parent, _) then result = true else result = false
17+
}
18+
1319
from TypeParamType tp, string name, CompositeType bound, TypeParamParentObject parent, int idx
1420
where typeparam(tp, name, bound, parent, idx)
15-
select tp, name, bound, parent, idx, false
21+
select tp, name, bound, parent, idx, isFromReceiver(parent)

0 commit comments

Comments
 (0)