Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The one about named returns, err always being nil, why is err even in scope, seems like it should be a compile error to me? (I rarely write Go).


In the function signature, the return variable err is type error. Since it is named it is also defined and initialized as nil.

In the code, an error is found and it does not assign a value to err and just returns it as the error value.

So it returns nil as the error when it wants to return an error with a proper value.

The code should be something like:

    if ctx.Err() != nil {
      return 0, 0, ctx.Err()
    }




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: