4 ms·
> The interface tuple returned by a() is ([]int, nil), comparing this to nil, which is a (nil,nil) returns false(!) It's certainly a subtlety that can bite you
by vanderZwan 14y ago
> The interface tuple returned by a() is ([]int, nil), comparing this to nil, which is a (nil,nil) returns false(!)
It's certainly a subtlety that can bite you, but I'd say that in this form it is arguably more consistent: assigning a type to an interface and having that be nil is not the same as assigning nil to an interface - those two variables are not equal and should be treated as such.
- blablabla123 14y agoHow is this more consistent? This can produce nil pointer dereferences.
- vanderZwan 14y ago> those two variables are not equal and should be treated as such. In that sense. Don't get me wrong: I'm not saying it fixes other problems with nill pointers, and yes, it introduces an extra possibility for dereference problems. Just like you're allowed to call methods on nill pointers if it's a nill pointer to a type that has these methods. https://groups.google.com/forum/?fromgroups=#!searchin/golang-nuts/calling$20methods/golang-nuts/wcrZ3P1zeAk/WI88iQgFMvwJ https://groups.google.com/forum/?fromgroups=#!searchin/golan...