diff --git a/go/extractor/extractor.go b/go/extractor/extractor.go index f421688e52a..8c217837614 100644 --- a/go/extractor/extractor.go +++ b/go/extractor/extractor.go @@ -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) } } diff --git a/go/ql/lib/upgrades/b1341734d6870b105e5c9d168ce7dec25d7f72d0/typeparam.ql b/go/ql/lib/upgrades/b1341734d6870b105e5c9d168ce7dec25d7f72d0/typeparam.ql index 041c33577f7..05ceab70344 100644 --- a/go/ql/lib/upgrades/b1341734d6870b105e5c9d168ce7dec25d7f72d0/typeparam.ql +++ b/go/ql/lib/upgrades/b1341734d6870b105e5c9d168ce7dec25d7f72d0/typeparam.ql @@ -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)