Commit 3c1712db authored by Konstantin Shaposhnikov's avatar Konstantin Shaposhnikov Committed by Ian Lance Taylor

cmd/vet: fix shadow assignment check with complex rhs

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/16038Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 9e902f0f
...@@ -155,6 +155,8 @@ func (f *File) idiomaticShortRedecl(a *ast.AssignStmt) bool { ...@@ -155,6 +155,8 @@ func (f *File) idiomaticShortRedecl(a *ast.AssignStmt) bool {
return false return false
} }
} }
default:
return false
} }
} }
return true return true
......
...@@ -25,8 +25,9 @@ func ShadowRead(f *os.File, buf []byte) (err error) { ...@@ -25,8 +25,9 @@ func ShadowRead(f *os.File, buf []byte) (err error) {
_ = i _ = i
} }
if f != nil { 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" 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 return err
} }
} }
...@@ -52,3 +53,7 @@ func ShadowRead(f *os.File, buf []byte) (err error) { ...@@ -52,3 +53,7 @@ func ShadowRead(f *os.File, buf []byte) (err error) {
_, _ = err, x _, _ = err, x
return return
} }
func one() int {
return 1
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment