From 898f827b1c6fed535d8c2d3511f47d760b56d6b2 Mon Sep 17 00:00:00 2001 From: "Remi GASCOU (Podalirius)" <79218792+p0dalirius@users.noreply.github.com> Date: Sat, 18 Apr 2026 09:47:56 +0200 Subject: [PATCH] Fix LABEL inside block silently dropped (#2) --- src/script_parser.cpp | 6 ++++++ tests/test_script_parser.cpp | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/script_parser.cpp b/src/script_parser.cpp index acaaba4..a7ffc70 100644 --- a/src/script_parser.cpp +++ b/src/script_parser.cpp @@ -100,6 +100,12 @@ ParseResult ScriptParser::parse(const QVector &tokenLines) { continue; } + // LABEL must be at top level (labels are resolved against root->children only) + if (first == TokenType::LABEL && !blockStack.isEmpty()) { + error(line, "LABEL must be at the top level (not inside IF/WHILE/REPEAT/DEF)"); + continue; + } + // Parse the line into an AST node auto node = parseLine(tl); if (!node) continue; diff --git a/tests/test_script_parser.cpp b/tests/test_script_parser.cpp index 959a85d..ca24d99 100644 --- a/tests/test_script_parser.cpp +++ b/tests/test_script_parser.cpp @@ -72,6 +72,7 @@ class TestScriptParser : public QObject { void testFunctionReturn(); void testNestedDefError(); void testDefInsideBlockError(); + void testLabelInsideBlockError(); void testCallUndefinedFunction(); void testCallWrongArgCount(); void testDuplicateFunction(); @@ -682,6 +683,22 @@ void TestScriptParser::testDefInsideBlockError() { QVERIFY(found); } +void TestScriptParser::testLabelInsideBlockError() { + auto result = m_parser->parse( + "IF $X == \"1\"\n" + " LABEL inside\n" + "ENDIF\n" + "GOTO inside\n" + ); + QVERIFY(result.hasErrors()); + bool foundLabelError = false; + for (const auto &e : result.errors) { + if (e.line == 2 && e.message.contains("LABEL must be at the top level")) + foundLabelError = true; + } + QVERIFY(foundLabelError); +} + void TestScriptParser::testCallUndefinedFunction() { auto result = m_parser->parse("CALL nonexistent()"); QVERIFY(result.hasErrors());