From e239f1b3f2dd0c654d3cf3de093f9710f99fa0cb Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Thu, 13 Mar 2014 10:27:55 +1100 Subject: [PATCH] go.tools/cmd/vet: don't check for shadowing of blank identifier It's pointless. Also this fixes a crash, because the blank identifier no longer appears as a defined object after CL 74190043 so we were getting nil pointer violations. Even better, we get to re-enable a disabled test. LGTM=gri R=gri CC=golang-codereviews https://golang.org/cl/75140043 --- cmd/vet/shadow.go | 7 ++++--- cmd/vet/testdata/shadow.go | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/vet/shadow.go b/cmd/vet/shadow.go index 2ae54c35..bb230eee 100644 --- a/cmd/vet/shadow.go +++ b/cmd/vet/shadow.go @@ -91,9 +91,6 @@ func (pkg *Package) growSpan(ident *ast.Ident, obj types.Object) { // checkShadowAssignment checks for shadowing in a short variable declaration. func (f *File) checkShadowAssignment(a *ast.AssignStmt) { - // TODO(r) remove this return once tests pass again - return - if !vet("shadow") { return } @@ -192,6 +189,10 @@ func (f *File) checkShadowDecl(d *ast.GenDecl) { // checkShadowing checks whether the identifier shadows an identifier in an outer scope. func (f *File) checkShadowing(ident *ast.Ident) { + if ident.Name == "_" { + // Can't shadow the blank identifier. + return + } obj := f.pkg.defs[ident] if obj == nil { return diff --git a/cmd/vet/testdata/shadow.go b/cmd/vet/testdata/shadow.go index d1313048..34a68068 100644 --- a/cmd/vet/testdata/shadow.go +++ b/cmd/vet/testdata/shadow.go @@ -17,8 +17,7 @@ func ShadowRead(f *os.File, buf []byte) (err error) { _ = err } if f != nil { - // TODO(r) enable this error again once tests pass - _, err := f.Read(buf) // DISABLED ERROR "declaration of err shadows declaration at testdata/shadow.go:13" + _, err := f.Read(buf) // ERROR "declaration of err shadows declaration at testdata/shadow.go:13" if err != nil { return err }