summaryrefslogtreecommitdiff
path: root/basic
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2019-12-07 15:27:08 +0100
committerXisco Faulí <xiscofauli@libreoffice.org>2019-12-09 12:04:46 +0100
commitbcfe36586c6bd07cef3c2ba39abd38bc9b6ab097 (patch)
tree471718ccf7f174eb51451358e3aa5d1c40740e3b /basic
parent87b421d25ef79e197d344e6bd515f1eadd06bfc9 (diff)
tdf#59327: DIM should fail in procedures when same-name argument is present
Change-Id: I0a6828bd0b0c27018dc02c36ee207b8666f88ec0 Reviewed-on: https://gerrit.libreoffice.org/84682 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> (cherry picked from commit 840c3a662012c77b5972c869587acd15ee5a3f03) Reviewed-on: https://gerrit.libreoffice.org/84732 Reviewed-by: Xisco Faulí <xiscofauli@libreoffice.org>
Diffstat (limited to 'basic')
-rw-r--r--basic/CppunitTest_basic_macros.mk1
-rw-r--r--basic/qa/cppunit/basictest.cxx3
-rw-r--r--basic/qa/cppunit/basictest.hxx2
-rw-r--r--basic/qa/cppunit/test_complier_checks.cxx27
-rw-r--r--basic/source/comp/dim.cxx5
5 files changed, 36 insertions, 2 deletions
diff --git a/basic/CppunitTest_basic_macros.mk b/basic/CppunitTest_basic_macros.mk
index 0ca767e1ddba..2d9959c9b6c9 100644
--- a/basic/CppunitTest_basic_macros.mk
+++ b/basic/CppunitTest_basic_macros.mk
@@ -15,6 +15,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,basic_macros, \
basic/qa/cppunit/basictest \
basic/qa/cppunit/basic_coverage \
basic/qa/cppunit/test_append \
+ basic/qa/cppunit/test_complier_checks \
basic/qa/cppunit/test_language_conditionals \
basic/qa/cppunit/test_nested_struct \
basic/qa/cppunit/test_vba \
diff --git a/basic/qa/cppunit/basictest.cxx b/basic/qa/cppunit/basictest.cxx
index 9a414b7f5e1a..3a22c84e9007 100644
--- a/basic/qa/cppunit/basictest.cxx
+++ b/basic/qa/cppunit/basictest.cxx
@@ -108,12 +108,15 @@ bool MacroSnippet::Compile()
bool MacroSnippet::HasError() const { return mbError; }
+const ErrCode& MacroSnippet::getError() const { return maErrCode; }
+
IMPL_LINK( MacroSnippet, BasicErrorHdl, StarBASIC *, /*pBasic*/, bool)
{
fprintf(stderr,"(%d:%d)\n",
StarBASIC::GetLine(), StarBASIC::GetCol1());
fprintf(stderr,"Basic error: %s\n", OUStringToOString( StarBASIC::GetErrorText(), RTL_TEXTENCODING_UTF8 ).getStr() );
mbError = true;
+ maErrCode = StarBASIC::GetErrorCode();
return false;
}
diff --git a/basic/qa/cppunit/basictest.hxx b/basic/qa/cppunit/basictest.hxx
index 8b92acf93d69..c8d262ee6def 100644
--- a/basic/qa/cppunit/basictest.hxx
+++ b/basic/qa/cppunit/basictest.hxx
@@ -24,6 +24,7 @@ class MacroSnippet
{
private:
bool mbError;
+ ErrCode maErrCode;
BasicDLL maDll; // we need a dll instance for resource manager etc.
SbModuleRef mpMod;
StarBASICRef mpBasic;
@@ -46,6 +47,7 @@ public:
DECL_LINK( BasicErrorHdl, StarBASIC *, bool );
bool HasError() const;
+ const ErrCode& getError() const;
};
#endif
diff --git a/basic/qa/cppunit/test_complier_checks.cxx b/basic/qa/cppunit/test_complier_checks.cxx
new file mode 100644
index 000000000000..aad058040c31
--- /dev/null
+++ b/basic/qa/cppunit/test_complier_checks.cxx
@@ -0,0 +1,27 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sal/config.h>
+#include "basictest.hxx"
+#include <basic/sberrors.hxx>
+#include <unotest/bootstrapfixturebase.hxx>
+
+CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testRedefineArgument)
+{
+ MacroSnippet aMacro("Sub doUnitTest(argName)\n"
+ " If False Then\n"
+ " Dim argName\n"
+ " End If\n"
+ "End Sub\n");
+ aMacro.Compile();
+ CPPUNIT_ASSERT(aMacro.HasError());
+ CPPUNIT_ASSERT_EQUAL(ERRCODE_BASIC_VAR_DEFINED, aMacro.getError().StripDynamic());
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/basic/source/comp/dim.cxx b/basic/source/comp/dim.cxx
index bfe8b3184b36..d6b2bff6ccc6 100644
--- a/basic/source/comp/dim.cxx
+++ b/basic/source/comp/dim.cxx
@@ -318,8 +318,9 @@ void SbiParser::DefVar( SbiOpcode eOp, bool bStatic )
}
if( pOld && !(eOp == SbiOpcode::REDIM_ || eOp == SbiOpcode::REDIMP_) )
{
- if( pDef->GetScope() == SbLOCAL && pOld->GetScope() != SbLOCAL )
- pOld = nullptr;
+ if( pDef->GetScope() == SbLOCAL )
+ if (auto eOldScope = pOld->GetScope(); eOldScope != SbLOCAL && eOldScope != SbPARAM)
+ pOld = nullptr;
}
if( pOld )
{