*The deferred function literal refers to a named return variable.Changing 
it to an unnamed one will cause the program to no longercompile.*
Interesting....

https://play.golang.org/p/jnRn4Bv98xS

See the example on the Go Playground.

Jan, someone can explain to me why it will no longer compile?

- amnon

On Sunday, 31 January 2021 at 11:19:23 UTC Jan Mercl wrote:

> On Sun, Jan 31, 2021 at 8:04 AM Amnon <amn...@gmail.com> wrote:
>
> > I really do not like code like
> > defer func() {
> > if cerr := f.Close(); cerr != nil && err == nil {
> > err = cerr
> > }
> > }()
> ..
> > If somebody later
> > changes the function to return unnamed values, this defer will silently 
> fail.
>
> The deferred function literal refers to a named return variable.
> Changing it to an unnamed one will cause the program to no longer
> compile.
>

-- 
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/9ea4a4c1-7ec2-43f1-9ab4-bf0ef8132bafn%40googlegroups.com.

Reply via email to