aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Donovan <adonovan@google.com>2024-05-10 14:08:10 -0400
committerGopher Robot <gobot@golang.org>2024-05-10 18:25:38 +0000
commit487737a1960720c6595131017ff98eef1586fa04 (patch)
tree24749b706a0d0a23afce2d5eadcb7983e92c8b01
parent4cfd18098bc9ef6e8127f3fa5dc870ced2f73f56 (diff)
downloadgolang-x-tools-upstream-master.tar.gz
gopls/internal/golang: fix another crash in RenderPackageDocupstream-master
..also in the call to NewSignatureType (like golang/go#67287). This time it was caused by mutation of TypeParams, and an overly assertive check that they are new, so now we clone them. Fixes golang/go#67294 Change-Id: Id9e0af4b90a0da41efac9be98365d036d78a2c55 Reviewed-on: https://go-review.googlesource.com/c/tools/+/584406 Auto-Submit: Alan Donovan <adonovan@google.com> Reviewed-by: Robert Findley <rfindley@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
-rw-r--r--gopls/internal/golang/pkgdoc.go15
-rw-r--r--gopls/internal/test/integration/misc/webserver_test.go6
2 files changed, 19 insertions, 2 deletions
diff --git a/gopls/internal/golang/pkgdoc.go b/gopls/internal/golang/pkgdoc.go
index eb0314311..fac30ed2e 100644
--- a/gopls/internal/golang/pkgdoc.go
+++ b/gopls/internal/golang/pkgdoc.go
@@ -491,10 +491,21 @@ window.onload = () => {
// parameters 4+ with "invalid type", format,
// then post-process the string.
if sig.Params().Len() > 3 {
+
+ // Clone each TypeParam as NewSignatureType modifies them (#67294).
+ cloneTparams := func(seq *types.TypeParamList) []*types.TypeParam {
+ slice := make([]*types.TypeParam, seq.Len())
+ for i := range slice {
+ tparam := seq.At(i)
+ slice[i] = types.NewTypeParam(tparam.Obj(), tparam.Constraint())
+ }
+ return slice
+ }
+
sig = types.NewSignatureType(
sig.Recv(),
- typesSeqToSlice[*types.TypeParam](sig.RecvTypeParams()),
- typesSeqToSlice[*types.TypeParam](sig.TypeParams()),
+ cloneTparams(sig.RecvTypeParams()),
+ cloneTparams(sig.TypeParams()),
types.NewTuple(append(
typesSeqToSlice[*types.Var](sig.Params())[:3],
types.NewVar(0, nil, "", types.Typ[types.Invalid]))...),
diff --git a/gopls/internal/test/integration/misc/webserver_test.go b/gopls/internal/test/integration/misc/webserver_test.go
index 29f8607bf..18066ad33 100644
--- a/gopls/internal/test/integration/misc/webserver_test.go
+++ b/gopls/internal/test/integration/misc/webserver_test.go
@@ -29,6 +29,9 @@ package a
const A = 1
+type G[T any] int
+func (G[T]) F(int, int, int, int, int, int, int, ...int) {}
+
// EOF
`
Run(t, files, func(t *testing.T, env *Env) {
@@ -38,6 +41,9 @@ const A = 1
doc1 := get(t, uri1)
checkMatch(t, true, doc1, "const A =.*1")
+ // Regression test for signature truncation (#67287, #67294).
+ checkMatch(t, true, doc1, regexp.QuoteMeta("func (G[T]) F(int, int, int, ...)"))
+
// Check that edits to the buffer (even unsaved) are
// reflected in the HTML document.
env.RegexpReplace("a/a.go", "// EOF", "func NewFunc() {}")