basic/qa/cppunit/test_compiler_checks.cxx | 12 ++++++++++++ basic/source/comp/loops.cxx | 11 ++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-)
New commits: commit 44cdfa2eee54f6ead849fd998abe1c3c58b67398 Author: Mike Kaganski <[email protected]> AuthorDate: Thu May 29 12:24:37 2025 +0200 Commit: Mike Kaganski <[email protected]> CommitDate: Thu May 29 15:02:55 2025 +0200 tdf#166781: Emit correct expected token on missing End If Change-Id: I28fc1822d80c45416204f56a5763a804b2b1f5a8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185999 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> diff --git a/basic/qa/cppunit/test_compiler_checks.cxx b/basic/qa/cppunit/test_compiler_checks.cxx index d17916caa3eb..2aba8a32c22e 100644 --- a/basic/qa/cppunit/test_compiler_checks.cxx +++ b/basic/qa/cppunit/test_compiler_checks.cxx @@ -258,4 +258,16 @@ CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf162986_property_let_end_functi CPPUNIT_ASSERT(aMacro.HasError()); } +CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testMissingEndIf) +{ + MacroSnippet aMacro(u"Sub doUnitTest(argName) " + " If False Then " + "End Sub "_ustr); + aMacro.Compile(); + CPPUNIT_ASSERT(aMacro.HasError()); + CPPUNIT_ASSERT_EQUAL(ERRCODE_BASIC_BAD_BLOCK, aMacro.getError().GetCode()); + // Without the fix, this was "End Sub" + CPPUNIT_ASSERT_EQUAL(u"End If"_ustr, aMacro.getError().GetArg1()); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/basic/source/comp/loops.cxx b/basic/source/comp/loops.cxx index 35a4cafad168..bafe2cb7df57 100644 --- a/basic/source/comp/loops.cxx +++ b/basic/source/comp/loops.cxx @@ -58,7 +58,7 @@ void SbiParser::If() eTok = Peek(); if( IsEof() ) { - Error( ERRCODE_BASIC_BAD_BLOCK, IF ); bAbort = true; return; + Error( ERRCODE_BASIC_BAD_BLOCK, ENDIF ); bAbort = true; return; } } while( eTok == ELSEIF ) @@ -85,7 +85,7 @@ void SbiParser::If() eTok = Peek(); if( IsEof() ) { - Error( ERRCODE_BASIC_BAD_BLOCK, ELSEIF ); bAbort = true; return; + Error( ERRCODE_BASIC_BAD_BLOCK, ENDIF ); bAbort = true; return; } } } @@ -101,7 +101,12 @@ void SbiParser::If() } else if( eTok == ENDIF ) Next(); - + else + { + Error(ERRCODE_BASIC_BAD_BLOCK, ENDIF); + bAbort = true; + return; + } while( iJmp > 0 ) {
