Typed nils in Go 2
https://dave.cheney.net/2017/08/09/typed-nils-in-go-2 [dave.cheney.net]
2019-02-18 21:36
This is an experience report about a gotcha in Go that catches every Go programmer at least once. The following program is extracted from a larger version that caused my co-workers to lose several hours today.
You’ve probably realised the cause of this problem is the dreaded typed nil, a gotcha that has its own entry in the Go FAQ. The typed nil emerges as a result of the definition of a interface type; a structure which contains the concrete type of the value stored in the interface, and the value itself.
Typed nils are an entirely logical result of the way dynamic types, aka interfaces, are implemented, but are almost never what the programmer wanted.
The linked post is a good read as well: https://research.swtch.com/interfaces