You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
This simple program doesn't trigger shadowing warnings from go vet:
package main
func f() (string, error) {
return "bar", nil
}
func main() {
var c int
var b int
if true {
c, _ := f()
_ = c
var b string
_ = b
}
_ = c
_ = b
}
However, I think it would be useful to complain about the variable c shadowing the
previous declaration; the fact that they are of different types isn't obvious when using
:=. Attached is a patch to do that. After applying, vet complains about c, but not b.
Any thoughts?
It seems more useful to report shadowing of variables when the types *are* the same.
Have you run your patch against the standard library? How noisy are the reports?
If my understanding is correct, the check for different types is a blunt heuristic for
determining whether the shadowed variable would have worked in place of the shadowing
one or not. I personally think it's way too blunt, but now after a night's sleep this
might not be good enough either.
I'll run it against the std lib and see what happens.
by marko@trustly.com:
Attachments:
The text was updated successfully, but these errors were encountered: