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 <https://play.golang.org/p/KTNHCjuzQY>. Thanks Andrew, thanks folks!
On Sunday, June 26, 2016 at 3:49:51 PM UTC+2, Andrew Mezoni wrote: > > >> 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() { > *c.err = c.f() > } > func main() { > var err error > > closure03 := &closure03{err: &err, f: f} > > g := closure03.fn > > g() > fmt.Println(err) > } > func f() error { > return fmt.Errorf("Some error occurred") > } > > > https://play.golang.org/p/ji_8QW1hIr > > > -- 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.