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
}

?


On Sunday, June 26, 2016 at 9:55:13 PM UTC+2, Ian Lance Taylor wrote:
>
> On Sat, Jun 25, 2016 at 12:34 PM, Val <dele...@gmail.com <javascript:>> 
> wrote: 
> > Hello 
> > It seems that this code doesn't compile : 
> > 
> > func main() { 
> >     var err error 
> >     err = f() 
> > } 
> > 
> > prog.go:8: err declared and not used 
> > 
> > 
> > but this one does : 
> > 
> > func main() { 
> >     var err error 
> >     g := func() { 
> >         err = f() 
> >     } 
> >     g() 
> > } 
> > 
> > Is the function binding regarded as a "use"?  Or does escape analysis 
> decide 
> > to not check too deep about never-read variables? 
> > 
> > Whether expected or not, I supposed this compiler behavior won't change, 
> > because of the Go1 compatibility promise. 
>
> While the rest of this thread gives something of an explanation, I 
> think this is a bug, and I think it could be fixed in a future 
> release.  This is https://golang.org/issue/3059. 
>
> The gccgo compiler does give an error for this code. 
>
> 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.

Reply via email to