mirror of
https://github.com/golang/go
synced 2024-11-18 13:04:46 -07:00
go.tools/cmd/vet: change message for range check
s/enclosed by function/captured by func literal/ Users complained. They often do. LGTM=josharian, adg R=golang-codereviews, josharian, nightlyone, minux, adg CC=golang-codereviews https://golang.org/cl/132080043
This commit is contained in:
parent
ba91af23b8
commit
671b9204b8
@ -63,7 +63,7 @@ func checkRangeLoop(f *File, node ast.Node) {
|
||||
return true
|
||||
}
|
||||
if key != nil && id.Obj == key.Obj || val != nil && id.Obj == val.Obj {
|
||||
f.Bad(id.Pos(), "range variable", id.Name, "enclosed by function")
|
||||
f.Bad(id.Pos(), "range variable", id.Name, "captured by func literal")
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
14
cmd/vet/testdata/rangeloop.go
vendored
14
cmd/vet/testdata/rangeloop.go
vendored
@ -10,24 +10,24 @@ func RangeLoopTests() {
|
||||
var s []int
|
||||
for i, v := range s {
|
||||
go func() {
|
||||
println(i) // ERROR "range variable i enclosed by function"
|
||||
println(v) // ERROR "range variable v enclosed by function"
|
||||
println(i) // ERROR "range variable i captured by func literal"
|
||||
println(v) // ERROR "range variable v captured by func literal"
|
||||
}()
|
||||
}
|
||||
for i, v := range s {
|
||||
defer func() {
|
||||
println(i) // ERROR "range variable i enclosed by function"
|
||||
println(v) // ERROR "range variable v enclosed by function"
|
||||
println(i) // ERROR "range variable i captured by func literal"
|
||||
println(v) // ERROR "range variable v captured by func literal"
|
||||
}()
|
||||
}
|
||||
for i := range s {
|
||||
go func() {
|
||||
println(i) // ERROR "range variable i enclosed by function"
|
||||
println(i) // ERROR "range variable i captured by func literal"
|
||||
}()
|
||||
}
|
||||
for _, v := range s {
|
||||
go func() {
|
||||
println(v) // ERROR "range variable v enclosed by function"
|
||||
println(v) // ERROR "range variable v captured by func literal"
|
||||
}()
|
||||
}
|
||||
for i, v := range s {
|
||||
@ -53,7 +53,7 @@ func RangeLoopTests() {
|
||||
var f int
|
||||
for x[0], f = range s {
|
||||
go func() {
|
||||
_ = f // ERROR "range variable f enclosed by function"
|
||||
_ = f // ERROR "range variable f captured by func literal"
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user