Putting anything that has a type in any interface makes it non nil.
(*foo)(nil) has a type.

On Fri, Dec 22, 2017, 17:38 Vincent Rischmann <zecmerqu...@gmail.com> 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.
>
-- 

-j

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