]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/vet: fix shadow assignment check with complex rhs
authorKonstantin Shaposhnikov <k.shaposhnikov@gmail.com>
Tue, 20 Oct 2015 16:39:27 +0000 (00:39 +0800)
committerIan Lance Taylor <iant@golang.org>
Wed, 21 Oct 2015 14:27:49 +0000 (14:27 +0000)
This change fixes shadow assignment check in cases when RHS is not an identifier
or a type assertion.

Fixes #12188

Change-Id: I0940df8d9c237ab8b8d3272eb6895e676c75c115
Reviewed-on: https://go-review.googlesource.com/16038
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/vet/shadow.go
src/cmd/vet/testdata/shadow.go

index 2149e70ce2890c0ac8d52561f05f2f427e7c2365..5d0d6b5bf5aea04a485cd367b10c2e6240f08464 100644 (file)
@@ -155,6 +155,8 @@ func (f *File) idiomaticShortRedecl(a *ast.AssignStmt) bool {
                                        return false
                                }
                        }
+               default:
+                       return false
                }
        }
        return true
index 34a680681be337baa4ab0aa4e96e1338e820c33f..241109f4eee6ebed48227469c457df3061b84021 100644 (file)
@@ -25,8 +25,9 @@ func ShadowRead(f *os.File, buf []byte) (err error) {
                _ = i
        }
        if f != nil {
+               x := one()               // ERROR "declaration of x shadows declaration at testdata/shadow.go:14"
                var _, err = f.Read(buf) // ERROR "declaration of err shadows declaration at testdata/shadow.go:13"
-               if err != nil {
+               if x == 1 && err != nil {
                        return err
                }
        }
@@ -52,3 +53,7 @@ func ShadowRead(f *os.File, buf []byte) (err error) {
        _, _ = err, x
        return
 }
+
+func one() int {
+       return 1
+}