Skip to content

Commit

Permalink
cmd/vet: teach vet about ast.AliasSpec
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
josharian authored and rsc committed Nov 3, 2016
1 parent 10f7574 commit aa8c8e7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/cmd/vet/copylock.go
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions src/cmd/vet/shadow.go
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/cmd/vet/testdata/copylock.go
@@ -1,6 +1,7 @@
package testdata

import (
"runtime"
"sync"
"sync/atomic"
)
Expand Down Expand Up @@ -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

0 comments on commit aa8c8e7

Please sign in to comment.