I don't think you're right that interfaces are implemented as a pointer to a struct. The struct is inline like any other struct, and it contains a pointer to a type and a pointer to the value, like `([*Baz], nil)` in your example. The problem is that a nil interface in Go is compiled to `(nil, nil)` which is different.
That still makes this inexcusable of course.
Re:Proposal: Go should have generics
by lobster_johnson on Monday April 18, 2016 @10:45AM
(#11520278)
You're right, it was lurking in the back of my mind that it must be on the stack entirely.
I don't think using nil to represent uninitialized data is a major issue-- if it were possible to catch uninitialized but queried variables at compile-time, that could be an improvement, but we want to give the programmer control to declare and initialize variables separately.
I agree the second case is a little silly.
The most surprising nil wart, however, is this ugly monster:
This happens is because interfaces are indirections. They are implemented as a pointer to a struct containing a type and a pointer to the real value. The interface value can be nil, but so can the internal pointer. They are different things.I think supporting nils today is unforgivable, but the last one is just mind-boggling. There's no excuse.