mirror of
https://github.com/golang/go
synced 2024-11-05 14:46:11 -07:00
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
This commit is contained in:
parent
ea79d922e6
commit
e239f1b3f2
@ -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
|
||||
|
3
cmd/vet/testdata/shadow.go
vendored
3
cmd/vet/testdata/shadow.go
vendored
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user