File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change 1
1
//golangcitest:args -Ecopyloopvar
2
2
package testdata
3
3
4
+ import "fmt"
5
+
4
6
func copyloopvarCase1 () {
5
7
slice := []int {1 , 2 , 3 }
6
8
fns := make ([]func (), 0 , len (slice )* 2 )
7
9
for i , v := range slice {
8
10
i := i // want `It's unnecessary to copy the loop variable "i"`
9
11
fns = append (fns , func () {
10
- _ = i
12
+ fmt . Println ( i )
11
13
})
12
14
_v := v // want `It's unnecessary to copy the loop variable "v"`
13
15
fns = append (fns , func () {
14
- _ = _v
16
+ fmt . Println ( _v )
15
17
})
16
18
}
17
19
for _ , fn := range fns {
@@ -25,7 +27,7 @@ func copyloopvarCase2() {
25
27
for i := 1 ; i <= loopCount ; i ++ {
26
28
i := i // want `It's unnecessary to copy the loop variable "i"`
27
29
fns = append (fns , func () {
28
- _ = i
30
+ fmt . Println ( i )
29
31
})
30
32
}
31
33
for _ , fn := range fns {
You can’t perform that action at this time.
0 commit comments