If you set the var statement outside the main func, the issue is gone 
because err is then a "global" var.
Setting var inside main makes it a local "unused" var.
If the returning code must be discarded then _ = f() also solves the issue.

Regards,

On Saturday, June 25, 2016 at 9:34:57 PM UTC+2, Val wrote:
>
> Hello
> It seems that this code <https://play.golang.org/p/C5jbcieUS6> doesn't 
> compile :
>
> func main() {
>     var err error
>     err = f()
> }
>
> *prog.go:8: err declared and not used*
>
>
> but this one <https://play.golang.org/p/Y5zc4sLbtE> 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.
>
> Cheers
>  Val
>

-- 
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