1
0
mirror of https://github.com/golang/go synced 2024-11-20 06:34:40 -07:00

cmd/vet: teach vet about ast.AliasSpec

Fixes #17755

Change-Id: I1ad1edc382b1312d992963054eb82648cb5112d2
Reviewed-on: https://go-review.googlesource.com/32588
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
Josh Bleecher Snyder 2016-11-02 18:25:57 -07:00 committed by Russ Cox
parent 10f757486e
commit aa8c8e770e
3 changed files with 14 additions and 3 deletions

View File

@ -61,7 +61,10 @@ func checkCopyLocksGenDecl(f *File, gd *ast.GenDecl) {
return return
} }
for _, spec := range gd.Specs { for _, spec := range gd.Specs {
valueSpec := spec.(*ast.ValueSpec) valueSpec, ok := spec.(*ast.ValueSpec)
if !ok {
continue
}
for i, x := range valueSpec.Values { for i, x := range valueSpec.Values {
if path := lockPathRhs(f, x); path != nil { if path := lockPathRhs(f, x); path != nil {
f.Badf(x.Pos(), "variable declaration copies lock value to %v: %v", valueSpec.Names[i].Name, path) f.Badf(x.Pos(), "variable declaration copies lock value to %v: %v", valueSpec.Names[i].Name, path)

View File

@ -188,8 +188,7 @@ func checkShadowDecl(f *File, d *ast.GenDecl) {
for _, spec := range d.Specs { for _, spec := range d.Specs {
valueSpec, ok := spec.(*ast.ValueSpec) valueSpec, ok := spec.(*ast.ValueSpec)
if !ok { if !ok {
f.Badf(spec.Pos(), "invalid AST: var GenDecl not ValueSpec") continue
return
} }
// Don't complain about deliberate redeclarations of the form // Don't complain about deliberate redeclarations of the form
// var i = i // var i = i

View File

@ -1,6 +1,7 @@
package testdata package testdata
import ( import (
"runtime"
"sync" "sync"
"sync/atomic" "sync/atomic"
) )
@ -156,3 +157,11 @@ func AtomicTypesCheck() {
vP := &vX vP := &vX
vZ := &atomic.Value{} vZ := &atomic.Value{}
} }
// ensure we don't crash when we encounter aliases; issue 17755
var _ => runtime.MemProfileRate
const _ => runtime.Compiler
type _ => sync.Mutex