aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authorMark Freeman <mark@golang.org>2026-04-01 14:39:27 -0400
committerGopher Robot <gobot@golang.org>2026-04-01 19:21:11 -0700
commite7a2019a1b79e655452f86d5055b13e080aa89ac (patch)
treebd9e9359b348735958f6eca8a5adfd5d7d4faf7c /src/cmd
parent515b8bf22e7ebcd56c1d4c022aa9186ed5d1ecdc (diff)
downloadgo-e7a2019a1b79e655452f86d5055b13e080aa89ac.tar.xz
cmd/compile/internal/noder: split up objTypeParams
This splits objTypeParams into objTypeParams and objRecvTypeParams. The type parameters on a generic method and its receiver need to be reported separately to the reader. Change-Id: If9eb93ca66a5a5e4bdce71364627ff4bee110311 Reviewed-on: https://go-review.googlesource.com/c/go/+/761981 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Mark Freeman <markfreeman@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/compile/internal/noder/writer.go53
1 files changed, 33 insertions, 20 deletions
diff --git a/src/cmd/compile/internal/noder/writer.go b/src/cmd/compile/internal/noder/writer.go
index 027d7e0636..e7f7df76a9 100644
--- a/src/cmd/compile/internal/noder/writer.go
+++ b/src/cmd/compile/internal/noder/writer.go
@@ -925,10 +925,9 @@ func (w *writer) objDict(obj types2.Object, dict *writerDict) {
w.Len(len(dict.implicits))
tparams := objTypeParams(obj)
- ntparams := tparams.Len()
- w.Len(ntparams)
- for i := 0; i < ntparams; i++ {
- w.typ(tparams.At(i).Constraint())
+ w.Len(len(tparams))
+ for _, tparam := range tparams {
+ w.typ(tparam.Constraint())
}
nderived := len(dict.derived)
@@ -958,8 +957,7 @@ func (w *writer) objDict(obj types2.Object, dict *writerDict) {
for _, implicit := range dict.implicits {
w.Bool(implicit.Underlying().(*types2.Interface).IsMethodSet())
}
- for i := 0; i < ntparams; i++ {
- tparam := tparams.At(i)
+ for _, tparam := range tparams {
w.Bool(tparam.Underlying().(*types2.Interface).IsMethodSet())
}
@@ -2707,16 +2705,15 @@ type declCollector struct {
}
func (c *declCollector) withTParams(obj types2.Object) *declCollector {
- tparams := objTypeParams(obj)
- n := tparams.Len()
- if n == 0 {
+ tparams := slices.Concat(objRecvTypeParams(obj), objTypeParams(obj))
+ if len(tparams) == 0 {
return c
}
copy := *c
copy.implicits = copy.implicits[:len(copy.implicits):len(copy.implicits)]
- for i := 0; i < n; i++ {
- copy.implicits = append(copy.implicits, tparams.At(i))
+ for _, tparam := range tparams {
+ copy.implicits = append(copy.implicits, tparam)
}
return &copy
}
@@ -3149,26 +3146,42 @@ func fieldIndex(info *types2.Info, str *types2.Struct, key *syntax.Name) int {
panic(fmt.Sprintf("%s: %v is not a field of %v", key.Pos(), field, str))
}
+// objRecvTypeParams returns the receiver type parameters on the given object.
+func objRecvTypeParams(obj types2.Object) []*types2.TypeParam {
+ if f, ok := obj.(*types2.Func); ok {
+ return asTypeParamSlice(f.Signature().RecvTypeParams())
+ }
+ return nil
+}
+
// objTypeParams returns the type parameters on the given object.
-func objTypeParams(obj types2.Object) *types2.TypeParamList {
- switch obj := obj.(type) {
+func objTypeParams(obj types2.Object) []*types2.TypeParam {
+ switch t := obj.(type) {
case *types2.Func:
- sig := obj.Type().(*types2.Signature)
- if sig.Recv() != nil {
- return sig.RecvTypeParams()
- }
- return sig.TypeParams()
+ return asTypeParamSlice(t.Signature().TypeParams())
case *types2.TypeName:
switch t := obj.Type().(type) {
case *types2.Named:
- return t.TypeParams()
+ return asTypeParamSlice(t.TypeParams())
case *types2.Alias:
- return t.TypeParams()
+ return asTypeParamSlice(t.TypeParams())
}
}
return nil
}
+// asTypeParamSlice unpacks a types2.TypeParamList to a []types2.TypeParam
+func asTypeParamSlice(l *types2.TypeParamList) []*types2.TypeParam {
+ if l.Len() == 0 {
+ return nil
+ }
+ s := make([]*types2.TypeParam, l.Len())
+ for i := range l.Len() {
+ s[i] = l.At(i)
+ }
+ return s
+}
+
// splitNamed decomposes a use of a defined type into its original
// type definition and the type arguments used to instantiate it.
func splitNamed(typ *types2.Named) (*types2.TypeName, []types2.Type) {