contracts

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAnalyzer

func NewAnalyzer(config Config) *analysis.Analyzer

Types

type Config

type Config struct {
	FollowImports   bool
	ReportContracts bool
}

func NewConfig

func NewConfig() Config

type Contract

type Contract struct {
	Pos       token.Pos // contract position, used for positioning debug messages
	Condition string    // valid Go-syntax expression which if true, the contract is violated
	Names     []string  // unbound variables used by the condition
	Message   string    // error message to show on contract failure
}

type Function

type Function struct {
	Args      []string
	Contracts []Contract
}

func (*Function) AFact

func (*Function) AFact()

func (Function) MapArgs

func (fn Function) MapArgs(exprs []ast.Expr, info *types.Info) map[string]string

MapArgs converts list of expressions to strings and maps them to function argument names.

func (Function) Validate

func (fn Function) Validate(vars map[string]string) (*Contract, error)

Validate chackes all contracts for a function using the given function arguments.

If a contract is violated, that contract is returned.

Possible return values:

  • (contract, nil): a contract is violated, that contract is returned.
  • (nil, SomeError): one or more contracts failed, the first failure is returned.

If a contract failed and another one succeeded but violated, the error is nil and the violated contract is returned. In other words, don't worry that we cannot execute a contract if we have a meaningful error to show for another contract. That allows the analyzer to safely ignore contract errors.

type Result

type Result map[*types.Func]*Function

Jump to

Keyboard shortcuts

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