LABEL inside a nested block is silently dropped, producing a misleading 'GOTO target not found' error
@p0dalirius is already working on this.
Since Apr 18, 2026.
- Dominant language
- C++
- Stars
- 0
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
Summary
The parser accepts LABEL syntactically anywhere but only registers labels that appear at the top level of the script. A LABEL placed inside IF/ELSE/WHILE/REPEAT/DEF is silently discarded, and any subsequent GOTO to that label fails with a misleading GOTO target '<name>' not found error that points at the GOTO, not at the misplaced LABEL.
Location
- File:
src/script_parser.cpp - Lines / functions:
ScriptParser::parse()at L155–L164 (label collection walks onlyroot->children) - Related: L98–L101 (
DEFis explicitly rejected inside blocks;LABELis not)
Category
state-management
Severity
medium
Impact: scripts that mistakenly place LABEL inside a block fail at parse time with a confusing, misdirected error. The language reference (PROMPT.md) documents LABEL name / GOTO name (top-level only), so the constraint is intended but not enforced at the point it is violated.
Reproduction / Evidence
Verified by code analysis and runtime test:
ScriptParser parser;
auto r = parser.parse(
"IF $X == \"1\"\n"
" LABEL inside\n"
"ENDIF\n"
"GOTO inside\n"
);
// r.errors: [ line 4: "GOTO target 'inside' not found" ]
// r.labels: empty
The LABEL node is appended to the enclosing block's children (parser.cpp L108–L114). Label resolution at L155–L164 iterates only root->children, so the nested LABEL is never added to result.labels. Validation at L170–L175 then flags the GOTO as dangling.
Expected Behavior
The parser should emit a clear error at the LABEL line stating that LABEL must be at the top level (matching the existing handling of DEF at L98–L101). No error should then be emitted against the GOTO, or — if it is — it should be evidently secondary.
Actual Behavior
Nested LABEL is silently dropped. The only error the user sees references the GOTO line, making the root cause hard to diagnose.
Root Cause
The label-collection loop only examines root->children and does not recurse; the grammar does not refuse LABEL inside a block at the point it is parsed.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.