golang.org/x/tools/gopls@v0.15.3/internal/analysis/unusedvariable/testdata/src/assign/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 "fmt" 9 "os" 10 ) 11 12 type A struct { 13 b int 14 } 15 16 func singleAssignment() { 17 v := "s" // want `v.*declared (and|but) not used` 18 19 s := []int{ // want `s.*declared (and|but) not used` 20 1, 21 2, 22 } 23 24 a := func(s string) bool { // want `a.*declared (and|but) not used` 25 return false 26 } 27 28 if 1 == 1 { 29 s := "v" // want `s.*declared (and|but) not used` 30 } 31 32 panic("I should survive") 33 } 34 35 func noOtherStmtsInBlock() { 36 v := "s" // want `v.*declared (and|but) not used` 37 } 38 39 func partOfMultiAssignment() { 40 f, err := os.Open("file") // want `f.*declared (and|but) not used` 41 panic(err) 42 } 43 44 func sideEffects(cBool chan bool, cInt chan int) { 45 b := <-c // want `b.*declared (and|but) not used` 46 s := fmt.Sprint("") // want `s.*declared (and|but) not used` 47 a := A{ // want `a.*declared (and|but) not used` 48 b: func() int { 49 return 1 50 }(), 51 } 52 c := A{<-cInt} // want `c.*declared (and|but) not used` 53 d := fInt() + <-cInt // want `d.*declared (and|but) not used` 54 e := fBool() && <-cBool // want `e.*declared (and|but) not used` 55 f := map[int]int{ // want `f.*declared (and|but) not used` 56 fInt(): <-cInt, 57 } 58 g := []int{<-cInt} // want `g.*declared (and|but) not used` 59 h := func(s string) {} // want `h.*declared (and|but) not used` 60 i := func(s string) {}() // want `i.*declared (and|but) not used` 61 } 62 63 func commentAbove() { 64 // v is a variable 65 v := "s" // want `v.*declared (and|but) not used` 66 } 67 68 func fBool() bool { 69 return true 70 } 71 72 func fInt() int { 73 return 1 74 }