Skip to content

Commit 3c1712d

Browse files
kostya-shianlancetaylor
authored andcommitted
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/16038 Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 9e902f0 commit 3c1712d

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/cmd/vet/shadow.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ func (f *File) idiomaticShortRedecl(a *ast.AssignStmt) bool {
155155
return false
156156
}
157157
}
158+
default:
159+
return false
158160
}
159161
}
160162
return true

src/cmd/vet/testdata/shadow.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ func ShadowRead(f *os.File, buf []byte) (err error) {
2525
_ = i
2626
}
2727
if f != nil {
28+
x := one() // ERROR "declaration of x shadows declaration at testdata/shadow.go:14"
2829
var _, err = f.Read(buf) // ERROR "declaration of err shadows declaration at testdata/shadow.go:13"
29-
if err != nil {
30+
if x == 1 && err != nil {
3031
return err
3132
}
3233
}
@@ -52,3 +53,7 @@ func ShadowRead(f *os.File, buf []byte) (err error) {
5253
_, _ = err, x
5354
return
5455
}
56+
57+
func one() int {
58+
return 1
59+
}

0 commit comments

Comments
 (0)