Help us shape the future of Go! Take the 2026 Go Developer Survey

keyscoll

package
v1.6.11 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package keyscoll collects table keys from expressions for type inference.

This package extracts key information from table constructors and index expressions to support record type inference and map key type analysis.

Key Collection

For table constructors:

{ name = "foo", count = 1 }  -- keys: ["name", "count"]
{ [1] = "a", [2] = "b" }     -- integer keys

The package identifies whether a table has string keys (record-like), integer keys (array-like), or mixed keys.

Usage

Key collection supports:

  • Distinguishing arrays from records
  • Validating field access against known keys
  • Inferring map key types from index patterns

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildKeysCollectorDetector

func BuildKeysCollectorDetector(graph *cfg.Graph, moduleBindings *bind.BindingTable) func(*cfg.CallInfo, cfg.Point, int) cfg.SymbolID

BuildKeysCollectorDetector returns a callback that detects if a call is to a keys collector function and returns the symbol of the table argument.

Types

type KeysCollectorInfo

type KeysCollectorInfo struct {
	ParamIndex  int // Which parameter the keys come from (0-based)
	ReturnIndex int // Which return slot carries the keys table (0-based)
}

KeysCollectorInfo tracks that a function returns keys of one of its parameters.

func DetectKeysCollector

func DetectKeysCollector(fn *ast.FunctionExpr) *KeysCollectorInfo

DetectKeysCollector analyzes a function body to detect if it follows the "keys collector" pattern: creates a table, iterates with pairs over a param, inserts keys into the table, and returns it.

Pattern:

local keys = {}
for k in pairs(param) do
    table.insert(keys, k)
end
return keys

func DetectKeysCollectorWithBindings added in v1.6.0

func DetectKeysCollectorWithBindings(fn *ast.FunctionExpr, moduleBindings *bind.BindingTable) *KeysCollectorInfo

DetectKeysCollectorWithBindings also rejects a module-reassigned pairs global.

Jump to

Keyboard shortcuts

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