func (o *Object) ReturnSomething() int {
if o == nil {
return 0
}
return o.SomeOtherValue
}
It is also therefore legal to return in an interface value a nil pointer to a struct of a particular kind, and therefore "an interface containing a nil pointer of a particular type" and "an interface containing nothing at all" are fundamentally different things that can not be collapsed together.So as Vendan says, it is just part of the language. All languages have this sort of wart in them, where two or more perfectly sensible decisions interact to create something that isn't sensible at first glance.
(I'm still in favor of going back in time and changing Go to have non-nillable values, but that ship has certainly sailed.)