Skip to content

never-nil-comparison

Detect nil checks on values proven to be non-nil.

Updated View as Markdown

Default severity: error

Fresh allocations, make results, functions, closures, and values flowing exclusively from those sources cannot be nil. Comparing them with nil has a fixed result and often means the wrong value was checked.

Bad

values := make([]int, 0); if values == nil { unreachable() }

Good

var values []int; if values == nil { initialize() }
Navigation

Type to search…

↑↓ navigate↵ selectEsc close