1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
//golangcitest:args -Ewastedassign
package testdata
import "strings"
func pa(x int) int {
return x + 1
}
func multiple(val interface{}, times uint) interface{} {
switch hogehoge := val.(type) {
case int:
return 12
case string:
return strings.Repeat(hogehoge, int(times))
default:
return nil
}
}
func noUseParams(params string) int {
a := 12
println(a)
return a
}
func f(param int) int {
println(param)
useOutOfIf := 1212121 // want "assigned to useOutOfIf, but reassigned without using the value"
ret := 0
if false {
useOutOfIf = 200 // want "assigned to useOutOfIf, but never used afterwards"
return 0
} else if param == 100 {
useOutOfIf = 100 // want "assigned to useOutOfIf, but reassigned without using the value"
useOutOfIf = 201
useOutOfIf = pa(useOutOfIf)
useOutOfIf += 200 // want "assigned to useOutOfIf, but reassigned without using the value"
} else {
useOutOfIf = 100
useOutOfIf += 100
useOutOfIf = pa(useOutOfIf)
useOutOfIf += 200 // want "assigned to useOutOfIf, but reassigned without using the value"
}
if false {
useOutOfIf = 200 // want "assigned to useOutOfIf, but never used afterwards"
return 0
} else if param == 200 {
useOutOfIf = 100 // want "assigned to useOutOfIf, but reassigned without using the value"
useOutOfIf = 201
useOutOfIf = pa(useOutOfIf)
useOutOfIf += 200
} else {
useOutOfIf = 100
useOutOfIf += 100
useOutOfIf = pa(useOutOfIf)
useOutOfIf += 200
}
// useOutOfIf = 12
println(useOutOfIf)
useOutOfIf = 192
useOutOfIf += 100
useOutOfIf += 200 // want "assigned to useOutOfIf, but never used afterwards"
return ret
}
func checkLoopTest() int {
hoge := 12
noUse := 1111
println(noUse)
noUse = 1111 // want "assigned to noUse, but never used afterwards"
for {
if hoge == 14 {
break
}
hoge = hoge + 1
}
return hoge
}
func r(param int) int {
println(param)
useOutOfIf := 1212121
ret := 0
if false {
useOutOfIf = 200 // want "assigned to useOutOfIf, but never used afterwards"
return 0
} else if param == 100 {
ret = useOutOfIf
} else if param == 200 {
useOutOfIf = 100 // want "assigned to useOutOfIf, but reassigned without using the value"
useOutOfIf = 100
useOutOfIf = pa(useOutOfIf)
useOutOfIf += 200 // want "assigned to useOutOfIf, but reassigned without using the value"
}
useOutOfIf = 12
println(useOutOfIf)
useOutOfIf = 192
useOutOfIf += 100
useOutOfIf += 200 // want "assigned to useOutOfIf, but never used afterwards"
return ret
}
func mugen() {
var i int
var hoge int
for {
hoge = 5 // want "assigned to hoge, but reassigned without using the value"
// break
}
println(i)
println(hoge)
return
}
func noMugen() {
var i int
var hoge int
for {
hoge = 5
break
}
println(i)
println(hoge)
return
}
func reassignInsideLoop() {
bar := func(b []byte) ([]byte, error) { return b, nil }
var err error
var rest []byte
for {
rest, err = bar(rest)
if err == nil {
break
}
}
return
}
func reassignInsideLoop2() {
var x int = 0
var y int = 1
for i := 1; i < 3; i++ {
x += y
y *= 2 * i
}
println(x)
}
|