aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/noder
diff options
context:
space:
mode:
authorMark Freeman <mark@golang.org>2026-04-01 15:45:17 -0400
committerMark Freeman <mark@golang.org>2026-04-03 10:10:16 -0700
commitb9c77f8c00b09d3d17e603fa576e0148e501bd70 (patch)
treedfa63012cd4c06c1d2eb19b3507caaf520cb2574 /src/cmd/compile/internal/noder
parentae1edbeb2f77c8242ab7adf57b2449ae4740544d (diff)
downloadgo-b9c77f8c00b09d3d17e603fa576e0148e501bd70.tar.xz
cmd/compile/internal/noder: offset type parameter indices
When a writer goes to encode use of a type parameter, it only records an index because the writer knows all of the type parameters in scope for that object. The writer orders the type parameteres as implicits first, then receivers, then explicits actually on the object. Note that receivers *are* explicit type arguments, they're just inherited from the type. For instance, given: func (T[P]) m[Q, R any]() This has: - 0 implicits - 1 receiver - 2 explicits With this ordering, P is at 0, Q is at 1, and R is at 2. In contrast, inspecting TypeParam.index for Q yields 0, and for R yields 1; hence the offset is needed. Change-Id: If12f342e109fbc5935ba278f574ac2809c889335 Reviewed-on: https://go-review.googlesource.com/c/go/+/762021 Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Mark Freeman <markfreeman@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/cmd/compile/internal/noder')
-rw-r--r--src/cmd/compile/internal/noder/writer.go11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/cmd/compile/internal/noder/writer.go b/src/cmd/compile/internal/noder/writer.go
index 85686a481a..4944b7bd54 100644
--- a/src/cmd/compile/internal/noder/writer.go
+++ b/src/cmd/compile/internal/noder/writer.go
@@ -230,8 +230,7 @@ type itabInfo struct {
// typeParamIndex returns the index of the given type parameter within
// the dictionary. This may differ from typ.Index() when there are
-// implicit type parameters due to defined types declared within a
-// generic function or method.
+// implicit or receiver type parameters.
func (dict *writerDict) typeParamIndex(typ *types2.TypeParam) int {
for idx, implicit := range dict.implicits {
if implicit == typ {
@@ -239,7 +238,13 @@ func (dict *writerDict) typeParamIndex(typ *types2.TypeParam) int {
}
}
- return len(dict.implicits) + typ.Index()
+ for idx, receiver := range dict.receivers {
+ if receiver == typ {
+ return len(dict.implicits) + idx
+ }
+ }
+
+ return len(dict.implicits) + len(dict.receivers) + typ.Index()
}
// A derivedInfo represents a reference to an encoded generic Go type.