Go: Address review comments

This commit is contained in:
Jeroen Ketema
2026-07-14 10:23:43 +02:00
parent e0f0987b81
commit 09da46d8bd
2 changed files with 16 additions and 10 deletions

View File

@@ -2010,11 +2010,9 @@ func extractTypeParamDecls(tw *trap.Writer, fields *ast.FieldList, parent trap.L
}
func populateTypeParamParentsFromFunction(funcObj *types.Func) {
recvTypeParams := funcObj.Type().(*types.Signature).RecvTypeParams()
populateTypeParamParents(recvTypeParams, funcObj, true)
typeParams := funcObj.Type().(*types.Signature).TypeParams()
populateTypeParamParents(typeParams, funcObj, false)
signature := funcObj.Type().(*types.Signature)
populateTypeParamParents(signature.RecvTypeParams(), funcObj, true)
populateTypeParamParents(signature.TypeParams(), funcObj, false)
}
// 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,
return parentlbl, entry.isFromReceiver
}
func setTypeParamParent(tp *types.TypeParam, newobj types.Object, isFromReceiver bool) {
func setTypeParamParent(tp *types.TypeParam, parent types.Object, isFromReceiver bool) {
entry, exists := typeParamParent[tp]
newEntry := typeParamParentEntry{parent, isFromReceiver}
if !exists {
typeParamParent[tp] = typeParamParentEntry{newobj, isFromReceiver}
} else if entry.parent != newobj {
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)
typeParamParent[tp] = newEntry
} else if entry != newEntry {
log.Fatalf("Parent of type parameter '%s %s' being set to a different value: {'%s', %t}' vs {'%s', %t}",
tp.String(), tp.Constraint().String(), entry.parent, entry.isFromReceiver, parent, isFromReceiver)
}
}

View File

@@ -10,6 +10,12 @@ class TypeParamParentObject extends @typeparamparentobject {
string toString() { none() }
}
// In Go 1.26 and below, a type parameter is from a receiver exactly when its
// parent is a method.
boolean isFromReceiver(TypeParamParentObject parent) {
if methodreceivers(parent, _) then result = true else result = false
}
from TypeParamType tp, string name, CompositeType bound, TypeParamParentObject parent, int idx
where typeparam(tp, name, bound, parent, idx)
select tp, name, bound, parent, idx, false
select tp, name, bound, parent, idx, isFromReceiver(parent)