3 ms·
it appeared to be a typo, and as you suggest the compiler caught it var foo *Foo var err error if foo, err = getFoo(); err != nil { return
by flip_rect_red 9y ago
it appeared to be a typo, and as you suggest the compiler caught it
var foo *Foo
var err error
if foo, err = getFoo(); err != nil {
return nil, err
}
//foo is usable now
- lobster_johnson 9y agoThat solves nothing. The point was that you pollute the scope with error variables, leading to dangerous logic errors that can be hard to spot. Your snippet is no better than: foo, err := getFoo() if err != nil { return nil, err } "err" still ends up in the scope.