Along similar lines: WAT 15. Under what circumstances do you expect a nil var return to become non-nil? Did you even know that was possible?
Along similar lines: WAT 15. Under what circumstances do you expect a nil var return to become non-nil? Did you even know that was possible?
Yeah. Typed nils are a horrible, horrible feature: when you cast a value to an interface, it creates a fat pointer of (Type, Value). From a nil, that's (nil, nil) but from a nil Foo that's (Foo, nil). And since `==` just does a straight value comparison, (nil, nil) != (Foo, nil).
This actually has an official FAQ entry telling you to go fuck yourself: https://golang.org/doc/faq#nil_error
That said, the fact that the crowd only offered an incorrect guess four times out of 16 is telling. This really didn't have the same feel to me as the original WAT talk, which is really full of truly strange things.
Dump those rules for a much simpler insight:
When comparing interfaces, type and value must match to compare equal.
So, (nil, nil) compares NE to (*myFancyErrorType, nil) for the same reason that (float64, 0) and (uint16, 0) do.
It isn't all that complicated. I don't see a real and non-insane alternative to it. Do you?