Skip to content

Commit 36e7bf9

Browse files
committed
internal/lsp/analysis/unusedparams: add tests for generics
using the typeparams convention. Change-Id: I42094b75bd43937bdae099473d6241de887456b4 Reviewed-on: https://go-review.googlesource.com/c/tools/+/353289 Trust: Peter Weinberger <[email protected]> Run-TryBot: Peter Weinberger <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent db89b5a commit 36e7bf9

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2021 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package typeparams
6+
7+
import (
8+
"bytes"
9+
"fmt"
10+
"net/http"
11+
)
12+
13+
type parent[T any] interface {
14+
n(f T)
15+
}
16+
17+
type yuh[T any] struct {
18+
a T
19+
}
20+
21+
func (y *yuh[int]) n(f bool) {
22+
for i := 0; i < 10; i++ {
23+
fmt.Println(i)
24+
}
25+
}
26+
27+
func a[T comparable](i1 int, i2 T, i3 int) int { // want "potentially unused parameter: 'i2'"
28+
i3 += i1
29+
_ = func(z int) int { // want "potentially unused parameter: 'z'"
30+
_ = 1
31+
return 1
32+
}
33+
return i3
34+
}
35+
36+
func b[T any](c bytes.Buffer) { // want "potentially unused parameter: 'c'"
37+
_ = 1
38+
}
39+
40+
func z[T http.ResponseWriter](h T, _ *http.Request) { // want "potentially unused parameter: 'h'"
41+
fmt.Println("Before")
42+
}
43+
44+
func l(h http.Handler) http.Handler {
45+
return http.HandlerFunc(z[http.ResponseWriter])
46+
}
47+
48+
func mult(a, b int) int { // want "potentially unused parameter: 'b'"
49+
a += 1
50+
return a
51+
}
52+
53+
func y[T any](a T) {
54+
panic("yo")
55+
}

internal/lsp/analysis/unusedparams/unusedparams_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ import (
99

1010
"golang.org/x/tools/go/analysis/analysistest"
1111
"golang.org/x/tools/internal/lsp/analysis/unusedparams"
12+
"golang.org/x/tools/internal/typeparams"
1213
)
1314

1415
func Test(t *testing.T) {
1516
testdata := analysistest.TestData()
16-
analysistest.Run(t, testdata, unusedparams.Analyzer, "a")
17+
tests := []string{"a"}
18+
if typeparams.Enabled {
19+
tests = append(tests, "typeparams")
20+
}
21+
analysistest.Run(t, testdata, unusedparams.Analyzer, tests...)
1722
}

0 commit comments

Comments
 (0)