You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
songgao at Song-ThinkPad in /tmp
$ cat main.go
package main
func main() {
var a int
a = 2
}
songgao at Song-ThinkPad in /tmp
$ go run main.go
# command-line-arguments
./main.go:4: a declared and not used
songgao at Song-ThinkPad in /tmp
$ vim main.go
songgao at Song-ThinkPad in /tmp
$ cat main.go
package main
func main() {
var a int
func() {
a = 2
}()
}
songgao at Song-ThinkPad in /tmp
$ go run main.go
songgao at Song-ThinkPad in /tmp
$ echo $?
0
What did you expect to see?
The declared but unused variable gets caught even if it's assigned in a function closure.
What did you see instead?
Not caught.
P.S. Interestingly, the same error was successfully caught by :GoRename command (which uses gorename) in vim.
The text was updated successfully, but these errors were encountered:
bradfitz
changed the title
Unused variable is not caught if it's assigned in a function closure
cmd/compile: unused variable is not caught if it's assigned in a function closure
Jul 7, 2016
go version
)?go env
)?The declared but unused variable gets caught even if it's assigned in a function closure.
Not caught.
P.S. Interestingly, the same error was successfully caught by
:GoRename
command (which usesgorename
) in vim.The text was updated successfully, but these errors were encountered: