Fix LABEL inside block silently dropped (#2)#5
Open
p0dalirius wants to merge 1 commit intomainfrom
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked Issue
Closes #2
Root Cause
Label resolution in
ScriptParser::parse()iterates onlyroot->children, so anyLABELnode that has been appended to a nested block'schildren(because it appeared insideIF/WHILE/REPEAT/DEF) is silently dropped. The language reference already documentsLABELas top-level only, andDEFis already enforced to be top-level at parse time —LABELsimply lacked the equivalent guard. When a subsequentGOTOreferenced the dropped label, the only user-visible error pointed at theGOTO, not at the misplacedLABEL.Fix Description
Mirror the existing
DEFtop-level check immediately after it inScriptParser::parse(): when the first token of a line isLABELandblockStackis non-empty, emit"LABEL must be at the top level (not inside IF/WHILE/REPEAT/DEF)"on that line and skip the node so it is never appended to the block. This keeps the error attached to the offending line and consistent in wording with the existingDEFdiagnostic.How Verified
testLabelInsideBlockErrorcoveringLABEL inside IF ... ENDIFand asserting the error line number and message. It verifies the error is reported on theLABELline (line 2), not on the subsequentGOTO.src/script_parser.cppimmediately following theDEFguard; thecontinueensures the nestedLABELis not appended to the enclosing block, so the later recursive GOTO validation cannot be misled by a phantom label entry either.ctestgreen).Test Coverage
Added:
tests/test_script_parser.cpp::testLabelInsideBlockError— asserts that a nestedLABELproduces a top-level-only error on its own line.Scope of Change
src/script_parser.cpp,tests/test_script_parser.cppRisk and Rollout
Local change. Previously-valid scripts (where
LABELalready appeared only at the top level) are unaffected. Scripts that unintentionally nested aLABELwill now see a clear error on the correct line instead of a misdirectedGOTO target '<name>' not foundmessage; this is the intended improvement.