smithery/JamesPrial

go-nil-pointer

Pointer receiver nil safety - methods can be called on nil

Installation

$ npx skills add smithery/JamesPrial --skill go-nil-pointer

Similar popular skills

Related neighbors and high-traction skills in the same topics — useful to compare before installing.

Also in this package

Other skills from smithery/JamesPrial · top by installs.

npx skills add smithery/JamesPrial

Browse all from smithery/JamesPrial

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Not declared
Cursor Not declared
Codex Not declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Not declared
Cline Not declared
OpenCode Not declared

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 1,120 B
  • docs SUMMARY.md 80 B

History

  1. First recorded snapshot · 0 installs

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
}

CORRECT - Handle nil receiver

type Tree struct {
    Value int
    Left  *Tree
    Right *Tree
}

func (t *Tree) Sum() int {
    if t == nil {
        return 0  // Nil tree has sum of 0
    }
    return t.Value + t.Left.Sum() + t.Right.Sum()
}

// Now safe to call
var tree *Tree  // nil
sum := tree.Sum()  // Returns 0, no panic

Use Cases

Nil receiver pattern enables elegant recursive algorithms and optional behavior.

Quick Fix

  • Check if receiver is nil at method start
  • Define sensible zero behavior for nil receiver
  • Document whether methods are nil-safe

When NOT to Use

If nil receiver doesn't make semantic sense, panic early with clear message.