[go-nuts] Re: Unused var written in closure

2016-06-26 Thread Val
If such an implicit closure struct is implicitly what happens under the hood, then this is a very good explanation of the behavior. And indeed taking the address of err is regarded as a use . Thanks Andrew, thanks folks! On Sunday, June 26, 2016 at 3:49:51 P

[go-nuts] Re: Unused var written in closure

2016-06-26 Thread Andrew Mezoni
>> If you set the var statement outside the main func, the issue is gone because err is then a "global" var. Not quite correct. This is how it work and why `err` is used: package main import "fmt" type closure03 struct { err *error f func() error } func (c *closure03) fn() {

[go-nuts] Re: Unused var written in closure

2016-06-26 Thread Constantin Konstantinidis
The official statement is here https://golang.org/doc/faq#unused_variables_and_imports Compiling methods details are slightly above. On Sunday, June 26, 2016 at 3:15:15 PM UTC+2, Hotei wrote: > > > > On Saturday, June 25, 2016 at 3:34:57 PM UTC-4, Val wrote: >> >> Hello >> It seems that this code

[go-nuts] Re: Unused var written in closure

2016-06-26 Thread Hotei
On Saturday, June 25, 2016 at 3:34:57 PM UTC-4, Val 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

[go-nuts] Re: Unused var written in closure

2016-06-26 Thread Andrew Mezoni
But what you want if it (`err`) really not used in your example? func main() { var err error err = f() } -- 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

Re: [go-nuts] Re: Unused var written in closure

2016-06-26 Thread 'Murat Knecht' via golang-nuts
While that fixes the compile issue, the question remains: ‘Is the function binding regarded as a "use"?’ I, too, am interested in understanding *why* the compiler declares this closure non-usage as “fine”. On 06/26/2016 07:28 PM, Constantin Konstantinidis wrote: > If you set the var statement ou

[go-nuts] Re: Unused var written in closure

2016-06-26 Thread Constantin Konstantinidis
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, Va