Lua.Compiler.GotoValidation (Lua v1.0.0-rc.3)

View Source

Static legality check for goto / ::label:: (Lua 5.3 §3.3.4).

PUC-Lua rejects illegal gotos at compile time; this pass mirrors that so both VM engines refuse the same programs before either goto resolver runs. It walks the AST function by function (gotos never cross a function boundary) and reports the first violation as {:error, message}:

  • a label defined twice in the same block — label '%s' already defined;
  • a goto whose label is not visible from its block or any enclosing one (undefined, or hidden inside a nested/sibling block) — no visible label '%s' for goto;
  • a forward goto that jumps into the scope of a local — i.e. it crosses a local declaration that is still in scope at the target label, and the label is not at the end of its block — jumps into the scope of local '%s'.

Active-local counts (nact) are tracked function-wide, like PUC's nactvar. When a goto leaves a block unresolved its count is clamped to the block's entry level (mirroring PUC's leaveblock), so the local-scope check stays sound across block boundaries.

Summary

Functions

Validate every function in chunk. Returns :ok or {:error, message}.

Functions

validate(chunk)

@spec validate(Lua.AST.Chunk.t()) :: :ok | {:error, String.t()}

Validate every function in chunk. Returns :ok or {:error, message}.