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