From aa8c8e770e6db895405b66d38867c2368d94024a Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Wed, 2 Nov 2016 18:25:57 -0700 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Russ Cox --- src/cmd/vet/copylock.go | 5 ++++- src/cmd/vet/shadow.go | 3 +-- src/cmd/vet/testdata/copylock.go | 9 +++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/cmd/vet/copylock.go b/src/cmd/vet/copylock.go index 31c1257a47..e8f94fc685 100644 --- a/src/cmd/vet/copylock.go +++ b/src/cmd/vet/copylock.go @@ -61,7 +61,10 @@ func checkCopyLocksGenDecl(f *File, gd *ast.GenDecl) { return } for _, spec := range gd.Specs { - valueSpec := spec.(*ast.ValueSpec) + valueSpec, ok := spec.(*ast.ValueSpec) + if !ok { + continue + } for i, x := range valueSpec.Values { if path := lockPathRhs(f, x); path != nil { f.Badf(x.Pos(), "variable declaration copies lock value to %v: %v", valueSpec.Names[i].Name, path) diff --git a/src/cmd/vet/shadow.go b/src/cmd/vet/shadow.go index 29c952fd88..764129d94c 100644 --- a/src/cmd/vet/shadow.go +++ b/src/cmd/vet/shadow.go @@ -188,8 +188,7 @@ func checkShadowDecl(f *File, d *ast.GenDecl) { for _, spec := range d.Specs { valueSpec, ok := spec.(*ast.ValueSpec) if !ok { - f.Badf(spec.Pos(), "invalid AST: var GenDecl not ValueSpec") - return + continue } // Don't complain about deliberate redeclarations of the form // var i = i diff --git a/src/cmd/vet/testdata/copylock.go b/src/cmd/vet/testdata/copylock.go index 35ed766f1d..52ac29c47c 100644 --- a/src/cmd/vet/testdata/copylock.go +++ b/src/cmd/vet/testdata/copylock.go @@ -1,6 +1,7 @@ package testdata import ( + "runtime" "sync" "sync/atomic" ) @@ -156,3 +157,11 @@ func AtomicTypesCheck() { vP := &vX vZ := &atomic.Value{} } + +// ensure we don't crash when we encounter aliases; issue 17755 + +var _ => runtime.MemProfileRate + +const _ => runtime.Compiler + +type _ => sync.Mutex