]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/vet: teach vet about ast.AliasSpec
authorJosh Bleecher Snyder <josharian@gmail.com>
Thu, 3 Nov 2016 01:25:57 +0000 (18:25 -0700)
committerRuss Cox <rsc@golang.org>
Thu, 3 Nov 2016 13:32:05 +0000 (13:32 +0000)
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>
src/cmd/vet/copylock.go
src/cmd/vet/shadow.go
src/cmd/vet/testdata/copylock.go

index 31c1257a47017401a53811c7d874608bf85f0de2..e8f94fc685672d1deee2a9cb05339d6695cf2a40 100644 (file)
@@ -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)
index 29c952fd8858eae7fb8a4d1747d7798e141e8444..764129d94cb10de9fe6e9ba2f6d944b3daa3a8c9 100644 (file)
@@ -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
index 35ed766f1da7e26010bcd7d3285c534c5ebf8b83..52ac29c47c51f93b09460f1ce2e2fff231c6f31e 100644 (file)
@@ -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