...

Package nilness

import "golang.org/x/tools/go/analysis/passes/nilness"
Overview
Index
Subdirectories

Overview ▾

Package nilness inspects the control-flow graph of an SSA function and reports errors such as nil pointer dereferences and degenerate nil pointer comparisons.

Index ▾

Package files

nilness.go

Constants

const Doc = `check for redundant or impossible nil comparisons

The nilness checker inspects the control-flow graph of each function in
a package and reports nil pointer dereferences and degenerate nil
pointers. A degenerate comparison is of the form x==nil or x!=nil where x
is statically known to be nil or non-nil. These are often a mistake,
especially in control flow related to errors.

This check reports conditions such as:

    if f == nil { // impossible condition (f is a function)
    }

and:

    p := &v
    ...
    if p != nil { // tautological condition
    }

and:

    if p == nil {
        print(*p) // nil dereference
    }
`

Variables

var Analyzer = &analysis.Analyzer{
    Name:     "nilness",
    Doc:      Doc,
    Run:      run,
    Requires: []*analysis.Analyzer{buildssa.Analyzer},
}

Subdirectories

Name Synopsis
..
cmd
nilness The nilness command applies the golang.org/x/tools/go/analysis/passes/nilness analysis to the specified packages of Go source code.