callresolver

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package callresolver is an archtest-internal convenience layer over internal/typeseval + internal/scanner for the recurring "walk every FuncDecl body, resolve a callee, assert a receiver" shape that several rules (audit_hash_input_frozen, serviceowned_handler_owner_check, changepassword_inactive_gate, …) previously hand-wrote and copy-drifted.

Scope: archtest internal helper. Not exported beyond tools/archtest — the public surface is the re-exports in tools/archtest/callresolver.go (archtest.WalkFuncDecls / WalkFuncDeclsAST / IsCallToPkgFunc / HasReceiver). Business archtest *_test.go files MUST use that façade, never import this package directly — enforced by PASS-FUNNEL-RESOLVE-01 (pass_funnel_test.go).

This package may import internal/typeseval and internal/scanner (internal↔internal is legal); it must NOT import package archtest, which would form an import cycle (archtest re-exports this package).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasReceiver

func HasReceiver(fn *ast.FuncDecl, typeName string) bool

HasReceiver reports whether fn declares a receiver whose base type name equals typeName, handling *T / T / T[P] / T[P,Q] via scanner.ReceiverTypeName. Returns false for free functions (no receiver) or a nil fn.

func IsCallToPkgFunc

func IsCallToPkgFunc(info *types.Info, call *ast.CallExpr, pkgPath, name string) bool

IsCallToPkgFunc reports whether call's callee resolves (import-alias / dot-import proof, generic-instantiation proof) to the package-level function (pkgPath, name). It strips generic-instantiation wrappers (*ast.IndexExpr / *ast.IndexListExpr) via [unwrapCallee] before delegating to typeseval.ResolvePackageRef.

Returns false for method calls (a SelectorExpr whose X is a value, not a package — use typeseval.ResolveMethodCall for those), nil info, or nil call.

func WalkFuncDecls

func WalkFuncDecls(
	files []*ast.File,
	info *types.Info,
	fset *token.FileSet,
	rel func(*ast.File) string,
	fn func(FuncDeclContext),
)

WalkFuncDecls is the decoupled engine behind archtest.WalkFuncDecls / WalkFuncDeclsAST. For each file it visits every top-level *ast.FuncDecl with a non-nil Body and invokes fn with a FuncDeclContext. rel maps a file to its module-relative slash path; a nil rel yields ctx.Rel == "".

It deliberately does NOT auto-skip _test.go / generated files — skip policy differs per rule (some skip test files, some skip generated, some filter by directory), so the callback decides. Bodiless decls (external / forward declarations) are skipped because they cannot enclose statements.

Uses scanner.EachInChildren[ast.FuncDecl] (depth-1) rather than a raw `range file.Decls` loop, keeping the engine itself SCANNER-FRAMEWORK-USAGE compliant. FuncDecls only exist at file top level (nested funcs are *ast.FuncLit, not FuncDecl), so depth-1 is complete.

Types

type FuncDeclContext

type FuncDeclContext struct {
	File *ast.File
	Func *ast.FuncDecl
	Info *types.Info // nil in AST-only mode
	// Fset is the caller-supplied FileSet. It is non-nil whenever the caller
	// supplied one (archtest.WalkFuncDecls passes p.Fset); a callback that
	// reads ctx.Fset.Position(...) must therefore only be used with a walker
	// that was given a non-nil FileSet.
	Fset *token.FileSet
	Rel  string
}

FuncDeclContext carries everything a per-FuncDecl visitor needs. In an AST-only walk Info is nil and Rel is "" (when no rel mapping was supplied).

Jump to

Keyboard shortcuts

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