On Sat, Jul 2, 2016 at 2:20 AM, <gordon.kl...@gmail.com> wrote: > More generally, this is https://github.com/golang/go/issues/10989. > > Such ineffectual assignments can be detected using > https://github.com/gordonklaus/ineffassign. > > An analysis showed that only a small fraction of such were bugs, making the > backwards-incompatible language change not worthwhile. > > @ianlancetaylor: It's interesting that gccgo gives an error for the case > given in this thread. Does it also flag other "assigned and not used", like > > func main() { > x := 0 > _ = x > x = 1 > } > > ?
gccgo does not warn about that. The warning issued by gc and gccgo is described by this implementation restriction in the spec: "A compiler may make it illegal to declare a variable inside a function body if the variable is never used" (https://golang.org/ref/spec#Variable_declarations). In the above function, the variable is used, so an error is not permitted by the spec. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.