KITFORMA · EDITORIAL ANSWER
Why is an error interface non-nil when its stored pointer is nil?
KitForma editorial guide. An interface carries a dynamic type and value. A typed nil pointer stored in error still supplies that type, so the interface need not equal nil.
Step-by-step answer
package main
import "fmt"
type failure struct{}
func (*failure) Error() string { return "failure" }
func main() {
var p *failure
var err error = p
fmt.Println(p == nil, err == nil)
}Sources and verification
Sources checked:
Scope: This editorial guide is based on the cited sources and tool behavior. A forum question or a query observed for our site does not establish market search volume, low competition, guaranteed rankings or inadequate answers elsewhere.
This editorial answer was prepared by KitForma with AI assistance. It is not presented as a real member question or an independent user review. Check the sources and the result with your own file; report corrections in the discussion.