go-nil-pointer
Installation
SKILL.md
Pointer Receiver Nil
Problem
Methods with pointer receivers can be called on nil. Must handle nil receiver.
Pattern
WRONG - Assume receiver is non-nil
type Tree struct {
Value int
Left *Tree
}
func (t *Tree) Sum() int {
return t.Value + t.Left.Sum() // PANIC if t or t.Left is nil
}