aboutsummaryrefslogtreecommitdiff
path: root/src/go/types/named.go
diff options
context:
space:
mode:
authorRobert Findley <rfindley@google.com>2021-09-15 17:18:37 -0400
committerRobert Findley <rfindley@google.com>2021-09-17 22:19:21 +0000
commit3fa35b5f9741d7d1c9a9e047057c7210da04fbba (patch)
tree7ffdc54df20d009a2f38bd40c6d4b8f4274b8e54 /src/go/types/named.go
parent3fa7dbeff53b56edd98f295bd0c34423c080ac57 (diff)
downloadgo-3fa35b5f9741d7d1c9a9e047057c7210da04fbba.tar.gz
go-3fa35b5f9741d7d1c9a9e047057c7210da04fbba.zip
go/types: ensure that we always get a new signature in expandNamed
CL 349412 introduced a bug when Checker.subst does not return a new signature: we were still setting the receiver to the instantiated type. I'm not sure how this could manifest in practice (other than confusing object strings). It's possible that I could generate a testdata-driven test for this, but in the interest of time I just added a test to verify object strings. Change-Id: I29bc8e1419ddc4574755c3def52d18cb71c738eb Reviewed-on: https://go-review.googlesource.com/c/go/+/350143 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/go/types/named.go')
-rw-r--r--src/go/types/named.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/go/types/named.go b/src/go/types/named.go
index 00fde16445..4a263410fc 100644
--- a/src/go/types/named.go
+++ b/src/go/types/named.go
@@ -309,6 +309,12 @@ func (check *Checker) completeMethod(env *Environment, m *Func) {
smap := makeSubstMap(origSig.RecvTypeParams().list(), rtyp.targs.list())
sig := check.subst(orig.pos, origSig, smap, env).(*Signature)
+ if sig == origSig {
+ // No substitution occurred, but we still need to create a copy to hold the
+ // instantiated receiver.
+ copy := *origSig
+ sig = &copy
+ }
sig.recv = NewParam(origSig.recv.pos, origSig.recv.pkg, origSig.recv.name, rtyp)
m.typ = sig