aboutsummaryrefslogtreecommitdiff
path: root/go/analysis/passes/tests
diff options
context:
space:
mode:
authorSuzy Mueller <suzmue@golang.org>2022-03-09 14:26:43 -0700
committerSuzy Mueller <suzmue@golang.org>2022-03-09 23:03:58 +0000
commit1670aadab3854e4d7bf4a7b9ec2628d6e627d6ff (patch)
tree49df992ace512b36c3823544d6f19b562b4c7c53 /go/analysis/passes/tests
parentfd72fd66f6942eba57acf68b91749da38ff16e9b (diff)
downloadgolang-x-tools-1670aadab3854e4d7bf4a7b9ec2628d6e627d6ff.tar.gz
go/analysis: fix bug with finding field type
There was a bug that attempted to index the type parameters list using the parameter index. Each field in the list can have multiple names declared so we need to instead search for the appropriate field. Fixes golang/go#51577 Change-Id: Iff4671eb71fc0a4f207f3d0f8835f30ae99bf275 Reviewed-on: https://go-review.googlesource.com/c/tools/+/391235 Trust: Suzy Mueller <suzmue@golang.org> Run-TryBot: Suzy Mueller <suzmue@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'go/analysis/passes/tests')
-rw-r--r--go/analysis/passes/tests/testdata/src/a/go118_test.go4
-rw-r--r--go/analysis/passes/tests/tests.go9
2 files changed, 12 insertions, 1 deletions
diff --git a/go/analysis/passes/tests/testdata/src/a/go118_test.go b/go/analysis/passes/tests/testdata/src/a/go118_test.go
index 059bd089c..eabc60c1b 100644
--- a/go/analysis/passes/tests/testdata/src/a/go118_test.go
+++ b/go/analysis/passes/tests/testdata/src/a/go118_test.go
@@ -51,6 +51,10 @@ func FuzzFuncSecondArgArrNotAllowed(f *testing.F) {
f.Fuzz(func(t *testing.T, i []int) {}) // want "fuzzing arguments can only have the following types: string, bool, float32, float64, int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, \\[\\]byte"
}
+func FuzzFuncConsecutiveArgNotAllowed(f *testing.F) {
+ f.Fuzz(func(t *testing.T, i, j string, k complex64) {}) // want "fuzzing arguments can only have the following types: string, bool, float32, float64, int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, \\[\\]byte"
+}
+
func FuzzFuncInner(f *testing.F) {
innerFunc := func(t *testing.T, i float32) {}
f.Fuzz(innerFunc) // ok
diff --git a/go/analysis/passes/tests/tests.go b/go/analysis/passes/tests/tests.go
index dcc38ca20..cdc79cb7a 100644
--- a/go/analysis/passes/tests/tests.go
+++ b/go/analysis/passes/tests/tests.go
@@ -154,7 +154,14 @@ func validateFuzzArgs(pass *analysis.Pass, params *types.Tuple, expr ast.Expr) {
for i := 1; i < params.Len(); i++ {
if !isAcceptedFuzzType(params.At(i).Type()) {
if isFuncLit {
- exprRange = fLit.Type.Params.List[i].Type
+ curr := 0
+ for _, field := range fLit.Type.Params.List {
+ curr += len(field.Names)
+ if i < curr {
+ exprRange = field.Type
+ break
+ }
+ }
}
pass.ReportRangef(exprRange, "fuzzing arguments can only have the following types: "+formatAcceptedFuzzType())
}