golang.org/x/tools/gopls@v0.15.3/internal/analysis/unusedparams/testdata/src/a/a.go (about) 1 // Copyright 2022 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 a 6 7 import ( 8 "bytes" 9 "fmt" 10 "net/http" 11 ) 12 13 type parent interface { 14 n(f bool) 15 } 16 17 type yuh struct { 18 a int 19 } 20 21 func (y *yuh) n(f bool) { 22 for i := 0; i < 10; i++ { 23 fmt.Println(i) 24 } 25 } 26 27 func a(i1 int, i2 int, i3 int) int { // want "unused parameter: i2" 28 i3 += i1 29 _ = func(z int) int { // want "unused parameter: z" 30 _ = 1 31 return 1 32 } 33 return i3 34 } 35 36 func b(c bytes.Buffer) { // want "unused parameter: c" 37 _ = 1 38 } 39 40 func z(h http.ResponseWriter, _ *http.Request) { // no report: func z is address-taken 41 fmt.Println("Before") 42 } 43 44 func l(h http.Handler) http.Handler { // want "unused parameter: h" 45 return http.HandlerFunc(z) 46 } 47 48 func mult(a, b int) int { // want "unused parameter: b" 49 a += 1 50 return a 51 } 52 53 func y(a int) { 54 panic("yo") 55 } 56 57 var _ = func(x int) {} // empty body: no diagnostic 58 59 var _ = func(x int) { println() } // want "unused parameter: x" 60 61 var ( 62 calledGlobal = func(x int) { println() } // want "unused parameter: x" 63 addressTakenGlobal = func(x int) { println() } // no report: function is address-taken 64 ) 65 66 func _() { 67 calledGlobal(1) 68 println(addressTakenGlobal) 69 } 70 71 func Exported(unused int) {} // no finding: an exported function may be address-taken 72 73 type T int 74 75 func (T) m(f bool) { println() } // want "unused parameter: f" 76 func (T) n(f bool) { println() } // no finding: n may match the interface method parent.n 77 78 func _() { 79 var fib func(x, y int) int 80 fib = func(x, y int) int { // want "unused parameter: y" 81 if x < 2 { 82 return x 83 } 84 return fib(x-1, 123) + fib(x-2, 456) 85 } 86 fib(10, 42) 87 }