Skip to content

Commit aa8c8e7

Browse files
josharianrsc
authored andcommitted
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Russ Cox <[email protected]>
1 parent 10f7574 commit aa8c8e7

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/cmd/vet/copylock.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ func checkCopyLocksGenDecl(f *File, gd *ast.GenDecl) {
6161
return
6262
}
6363
for _, spec := range gd.Specs {
64-
valueSpec := spec.(*ast.ValueSpec)
64+
valueSpec, ok := spec.(*ast.ValueSpec)
65+
if !ok {
66+
continue
67+
}
6568
for i, x := range valueSpec.Values {
6669
if path := lockPathRhs(f, x); path != nil {
6770
f.Badf(x.Pos(), "variable declaration copies lock value to %v: %v", valueSpec.Names[i].Name, path)

src/cmd/vet/shadow.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ func checkShadowDecl(f *File, d *ast.GenDecl) {
188188
for _, spec := range d.Specs {
189189
valueSpec, ok := spec.(*ast.ValueSpec)
190190
if !ok {
191-
f.Badf(spec.Pos(), "invalid AST: var GenDecl not ValueSpec")
192-
return
191+
continue
193192
}
194193
// Don't complain about deliberate redeclarations of the form
195194
// var i = i

src/cmd/vet/testdata/copylock.go

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package testdata
22

33
import (
4+
"runtime"
45
"sync"
56
"sync/atomic"
67
)
@@ -156,3 +157,11 @@ func AtomicTypesCheck() {
156157
vP := &vX
157158
vZ := &atomic.Value{}
158159
}
160+
161+
// ensure we don't crash when we encounter aliases; issue 17755
162+
163+
var _ => runtime.MemProfileRate
164+
165+
const _ => runtime.Compiler
166+
167+
type _ => sync.Mutex

0 commit comments

Comments
 (0)