| 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 |
|
| 18 |
|
| 19 |
|
| 20 |
if 1 == 1 { |
| 21 |
} |
| 22 |
|
| 23 |
panic("I should survive") |
| 24 |
} |
| 25 |
|
| 26 |
func noOtherStmtsInBlock() { |
| 27 |
} |
| 28 |
|
| 29 |
func partOfMultiAssignment() { |
| 30 |
_, err := os.Open("file") // want `declared (and|but) not used` |
| 31 |
panic(err) |
| 32 |
} |
| 33 |
|
| 34 |
func sideEffects(cBool chan bool, cInt chan int) { |
| 35 |
_ = <-c // want `declared (and|but) not used` |
| 36 |
_ = fmt.Sprint("") // want `declared (and|but) not used` |
| 37 |
_ = A{ // want `declared (and|but) not used` |
| 38 |
b: func() int { |
| 39 |
return 1 |
| 40 |
}(), |
| 41 |
} |
| 42 |
_ = A{<-cInt} // want `declared (and|but) not used` |
| 43 |
_ = fInt() + <-cInt // want `declared (and|but) not used` |
| 44 |
_ = fBool() && <-cBool // want `declared (and|but) not used` |
| 45 |
_ = map[int]int{ // want `declared (and|but) not used` |
| 46 |
fInt(): <-cInt, |
| 47 |
} |
| 48 |
_ = []int{<-cInt} // want `declared (and|but) not used` |
| 49 |
|
| 50 |
// (ill-typed) |
| 51 |
_ = func(s string) {}() // want `declared (and|but) not used` |
| 52 |
} |
| 53 |
|
| 54 |
func commentAbove() { |
| 55 |
// v is a variable |
| 56 |
} |
| 57 |
|
| 58 |
func commentBelow() { |
| 59 |
// v is a variable |
| 60 |
} |
| 61 |
|
| 62 |
func commentSpaceBelow() { |
| 63 |
|
| 64 |
// v is a variable |
| 65 |
} |
| 66 |
|
| 67 |
func fBool() bool { |
| 68 |
return true |
| 69 |
} |
| 70 |
|
| 71 |
func fInt() int { |
| 72 |
return 1 |
| 73 |
} |