See https://golang.org/doc/faq#nil_error

V.

On Friday, 22 December 2017 17:37:40 UTC+1, Vincent Rischmann wrote:
>
> Hello,
>
> while refactoring some code I encountered something strange regarding 
> redeclarations.
>
> Here is an example: https://play.golang.org/p/b7Bp2w2fWwk
> Somehow after redeclaring err when calling doIt, err is apparently not 
> nil, yet the functions never return anything other than nil.
>
> If I use a new variable it obviously works correctly. If I change doIt to 
> return an error interface instead of *foo it works too.
>
> I scratched my head for a good 10 minutes to understand why something 
> which appears nil would fail in a `if err != nil` check, so if someone has 
> an explanation as to what's happening that would be great.
>
> Thanks.
>

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