3 ms·
There's no such thing as an "untyped nil" in Go - nil is simply a zero value for "reference types" (i.e. pointers, maps, slices, channels, functions, interfaces
by bheadmaster 3y ago
There's no such thing as an "untyped nil" in Go - nil is simply a zero value for "reference types" (i.e. pointers, maps, slices, channels, functions, interfaces). It must be always typed. E.g., the following code:
package main
func main() {
foo := nil
_ = foo
}
Raises a compilation error:
./main.go:4:9: use of untyped nil in assignment
It's just that zero value (nil) of interface is not the same as a zero value (nil) of a pointer.
Casting a nil pointer to an interface does not create a nil interface, in the same way that casting a zero integer or an empty string to an interface{} (any) doesn't create a nil interface{} (any).