func MyFunc() error {
  v, err := doSomething()
  ...
  err := doAnotherthing()
}

That won't compile anyway; the second assignment would have to be

  err = doAnotherthing()

See: https://play.golang.org/p/pvNC7YHI88j

I do find this rather annoying, to the point where I'll stick a "var err 
error" at the top of a function rather than have the first assignment be 
different to the subsequent ones.  And yet, a single assignment is fine if 
you use the assign-and-test form, since this introduces a new variable 
which is only scoped to that block:

        // This is OK
if err := doAnotherthing(); err != nil {
return err
}

See: https://play.golang.org/p/4NKmFoX7uj2

It is also possible to use named return values and a naked return, although 
I get the impression this tends to be frowned upon.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/29e1b407-020f-48c6-bab9-7c4db44b038cn%40googlegroups.com.

Reply via email to