-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/vet: new shadow false positive in 1.8 when using range iteration #18613
Comments
/cc @josharian @robpike |
(I don't follow vet, but will conservatively mark this as Go1.8Maybe until owners say otherwise) |
I'm sure I'm missing something, but why is that a false positive? There is a |
Both of those messages from vet are correct. |
I've updated the program below to demonstrate why this is a false positive. Note that the block var strs []string
for _, str := range strs {
_ = str
str := "foo"
_ = str
} does not produce a vet warning. package main
import (
"context"
"strings"
)
func main() {
ctx := context.Background()
{
// go1.7.4, go1.8rc1: declaration of "ctx" shadows declaration at shadow.go:9
ctx, cancel := context.WithCancel(ctx)
_ = ctx
cancel()
}
var strs []string
for _, str := range strs {
_ = str
// no warning
str := "foo"
_ = str
}
for _, str := range strs {
// go1.8rc1: declaration of "str" shadows declaration at shadow.go:25
str := strings.Replace(str, "1", "2", -1)
_ = str
}
} Please reopen this issue. Either this is a false positive, or the behaviour is inconsistent. |
The behavior is inconsistent but the documentation also says the check is experimental. Honestly, I'd rather delete it than fix it; the approach is all wrong. |
I'd be OK with deleting it, for what it's worth. I believe tools like https://github.com/dominikh/go-staticcheck can fill in the gaps. |
Given the following program:
There are two
go tool vet -shadow
false positives present, but one of them is new in go1.8.This code is also at https://github.com/tamird/vet-bugs. cc @petermattis
The text was updated successfully, but these errors were encountered: