What is the difference between a nil interface and an interface holding a nil pointer (the 'typed nil' pitfall)?
Last updated
A nil interface has both type and data words nil. A "typed nil" holds a concrete type (e.g.
*T) with a nil pointer, so it is NOT equal tonil.Common trigger: returning a nil
*MyErrfrom a function whose return type iserror, makingerr != niltrue.Fix: return a literal
nilfor the interface, or check the concrete pointer before wrapping it.