Skip to content

compiler: check upvalue overflow and locate register errors - #556

Open
kimjooyoon wants to merge 2 commits into
yuin:masterfrom
kimjooyoon:fix-upvalue-count-overflow
Open

kimjooyoon wants to merge 2 commits into
yuin:masterfrom
kimjooyoon:fix-upvalue-count-overflow

Conversation

@kimjooyoon

@kimjooyoon kimjooyoon commented Oct 26, 2026 •

Copy link
Copy Markdown

Fixes #554.
Fixes #555.

Two compiler limit failures currently hide the useful diagnosis: a 256-upvalue count wraps and is accepted, while local/register overflow errors point at the enclosing function's start (line 0 for a main chunk).

This change:

  • Rejects upvalue counts above 255 before narrowing to uint8, preserving the existing 255-capture capacity.
  • Carries the declaration/header line into local-variable limit errors and retains the first source position that triggers register overflow accounting. The reported examples move from lines 0/5 to 202/206. Register limits, opcode accounting and error precedence remain unchanged.

Multiline declarations use their starting line; the AST does not retain individual name positions. The two issue fixes are separate commits in this PR.

Validation:

  • Original master 75f497656b1c6864139dd2a7d88cf96d09550814 reproduces two cases where overflowing upvalue counts incorrectly compile and nine incorrect source-location cases. Five accepted-input controls remain valid.
  • All 16 regression/control cases pass with both fixes together.
  • Required make build passed; generated files remain unchanged.
  • go test -p=2 -json -count=1 -timeout=90s ./... passed on Go 1.25.0 and 1.27.3, macOS/arm64, against the combined head.

AI assistance: OpenAI Codex (GPT-6) prepared the patches and tests; separate Codex agents reviewed them.

@kimjooyoon kimjooyoon changed the title compiler: reject upvalue counts above 255 compiler: check upvalue overflow and locate register errors Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant