Skip to content

impossible-interface-nil-comparison

Default severity: error

An interface is nil only when both its dynamic type and value are absent. Storing a typed nil pointer in an interface gives it a concrete dynamic type, so the interface itself is non-nil.

func result() error {
var problem *Problem
return problem // produces a non-nil error interface
}
if result() == nil { // reported as never true
handleSuccess()
}

Return an explicit nil interface on the success path instead.

func result(ok bool) error {
if ok {
return nil
}
return &Problem{}
}