copylock

Imports

Imports #

"bytes"
"fmt"
"go/ast"
"go/token"
"go/types"
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/passes/inspect"
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
"golang.org/x/tools/go/ast/inspector"
"golang.org/x/tools/internal/typeparams"
"golang.org/x/tools/internal/versions"

Constants & Variables

Analyzer var #

var Analyzer = *ast.UnaryExpr

Doc const #

const Doc = `check for locks erroneously passed by value

Inadvertently copying a value containing a lock, such as sync.Mutex or
sync.WaitGroup, may cause both copies to malfunction. Generally such
values should be referred to through a pointer.`

lockerType var #

var lockerType *types.Interface

Type Aliases

typePath type #

type typePath []string

Functions

String method #

String pretty-prints a typePath.

func (path typePath) String() string

checkCopyLocksAssign function #

checkCopyLocksAssign checks whether an assignment copies a lock.

func checkCopyLocksAssign(pass *analysis.Pass, assign *ast.AssignStmt, goversion string, parent ast.Node)

checkCopyLocksCallExpr function #

checkCopyLocksCallExpr detects lock copy in the arguments to a function call

func checkCopyLocksCallExpr(pass *analysis.Pass, ce *ast.CallExpr)

checkCopyLocksCompositeLit function #

checkCopyLocksCompositeLit detects lock copy inside a composite literal

func checkCopyLocksCompositeLit(pass *analysis.Pass, cl *ast.CompositeLit)

checkCopyLocksFunc function #

checkCopyLocksFunc checks whether a function might inadvertently copy a lock, by checking whether its receiver, parameters, or return values are locks.

func checkCopyLocksFunc(pass *analysis.Pass, name string, recv *ast.FieldList, typ *ast.FuncType)

checkCopyLocksGenDecl function #

checkCopyLocksGenDecl checks whether lock is copied in variable declaration.

func checkCopyLocksGenDecl(pass *analysis.Pass, gd *ast.GenDecl)

checkCopyLocksRange function #

checkCopyLocksRange checks whether a range statement might inadvertently copy a lock by checking whether any of the range variables are locks.

func checkCopyLocksRange(pass *analysis.Pass, r *ast.RangeStmt)

checkCopyLocksRangeVar function #

func checkCopyLocksRangeVar(pass *analysis.Pass, rtok token.Token, e ast.Expr)

checkCopyLocksReturnStmt function #

checkCopyLocksReturnStmt detects lock copy in return statement

func checkCopyLocksReturnStmt(pass *analysis.Pass, rs *ast.ReturnStmt)

init function #

Construct a sync.Locker interface type.

func init()

lockPath function #

lockPath returns a typePath describing the location of a lock value contained in typ. If there is no contained lock, it returns nil. The seen map is used to short-circuit infinite recursion due to type cycles.

func lockPath(tpkg *types.Package, typ types.Type, seen map[types.Type]bool) typePath

lockPathRhs function #

func lockPathRhs(pass *analysis.Pass, x ast.Expr) typePath

parent function #

parent returns the second from the last node on stack if it exists.

func parent(stack []ast.Node) ast.Node

run function #

func run(pass *analysis.Pass) (interface{}, error)

Generated with Arrow