check

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NestedAssign

type NestedAssign struct {
	Ident *ast.Ident
	Asgn  astutil.NodeIndex
}

NestedAssign contains information about a nested variable assign.

type NestedChecker

type NestedChecker struct {
	// contains filtered or unexported fields
}

NestedChecker tracks nested variable assignments.

func NewNestedChecker

func NewNestedChecker(enabled bool) NestedChecker

NewNestedChecker creates a new NestedChecker instance.

If enabled is false, nested assignment tracking is disabled, and the checker is a no-op that uses minimal memory.

func (*NestedChecker) NestedAssigned

func (nc *NestedChecker) NestedAssigned() []NestedAssign

NestedAssigned returns the list of variables that were assigned during an assignment.

func (*NestedChecker) TrackNestedAssignment added in v0.0.5

func (nc *NestedChecker) TrackNestedAssignment(v *types.Var, id *ast.Ident, assignmentDone token.Pos, asgn astutil.NodeIndex)

TrackNestedAssignment identifies nested assignments of variables and tracks their occurrences.

type ShadowChecker

type ShadowChecker struct {

	// Control-flow graph to test reachability
	*reachability.Graph
	// contains filtered or unexported fields
}

ShadowChecker tracks variable shadowing and usage of variables while they are shadowed.

It is designed to be embedded in other analyzers (like usageCollector) to add shadow detection capabilities.

func NewShadowChecker

func NewShadowChecker(enabled, firstUseOnly bool) ShadowChecker

NewShadowChecker creates a new ShadowChecker instance.

If enabled is false, shadow tracking is disabled, and the checker is a no-op that uses minimal memory.

func (*ShadowChecker) CheckDeclarationShadowing added in v0.0.5

func (sc *ShadowChecker) CheckDeclarationShadowing(scopes scope.UsageScope, variable *types.Var, shadowPos token.Pos)

CheckDeclarationShadowing checks if the variable shadows another in parent scopes and records it.

func (*ShadowChecker) CheckUseAfterShadowed added in v0.0.5

func (sc *ShadowChecker) CheckUseAfterShadowed(variable *types.Var, namePos token.Pos, use astutil.NodeIndex)

CheckUseAfterShadowed checks if the variable is used at the given position after shadowed. If it is, it records the usage.

func (*ShadowChecker) ShadowCheckerEnabled added in v0.0.5

func (sc *ShadowChecker) ShadowCheckerEnabled() bool

ShadowCheckerEnabled reports whether the shadow checker is enabled.

func (*ShadowChecker) UpdateShadows

func (sc *ShadowChecker) UpdateShadows(v *types.Var, id *ast.Ident, assignmentDone token.Pos)

UpdateShadows updates shadow tracking when variables are assigned at declaration scope. When a shadowed outer variable is reassigned, the shadow "ends" at that point, as the outer variable has a new value.

Note: This is lexically based, not control-flow sensitive.

func (*ShadowChecker) UpdateShadowsWithReachability added in v0.0.5

func (sc *ShadowChecker) UpdateShadowsWithReachability(v *types.Var, id *ast.Ident, assignmentDone token.Pos)

UpdateShadowsWithReachability updates shadow tracking when variables are assigned in a subscope.

func (*ShadowChecker) UsedAfterShadow

func (sc *ShadowChecker) UsedAfterShadow() []ShadowUse

UsedAfterShadow returns the list of variables that were used after being shadowed.

type ShadowUse

type ShadowUse struct {
	Var       *types.Var
	ShadowPos token.Pos
	Use       astutil.NodeIndex
}

ShadowUse contains information about a variable use after previously shadowed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL