summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2019-12-07 17:18:08 +0100
committerMike Kaganski <mike.kaganski@collabora.com>2019-12-07 20:01:16 +0100
commit0ed214fd8f64eca4f3192b1646595500d772b243 (patch)
treea07d43a21c4f85beb6db986d7fa2d24a8f49c52a
parent840c3a662012c77b5972c869587acd15ee5a3f03 (diff)
tdf#59327: two arguments with the same name is an error
Change-Id: I8d10487d6d6729de749a373feb0a8a349f2986e9 Reviewed-on: https://gerrit.libreoffice.org/84686 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r--basic/qa/cppunit/test_complier_checks.cxx9
-rw-r--r--basic/source/comp/dim.cxx9
-rw-r--r--basic/source/comp/symtbl.cxx4
-rw-r--r--basic/source/inc/symtbl.hxx2
4 files changed, 20 insertions, 4 deletions
diff --git a/basic/qa/cppunit/test_complier_checks.cxx b/basic/qa/cppunit/test_complier_checks.cxx
index aad058040c31..24b380ed2a9a 100644
--- a/basic/qa/cppunit/test_complier_checks.cxx
+++ b/basic/qa/cppunit/test_complier_checks.cxx
@@ -24,4 +24,13 @@ CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testRedefineArgument)
CPPUNIT_ASSERT_EQUAL(ERRCODE_BASIC_VAR_DEFINED, aMacro.getError().StripDynamic());
}
+CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testDoubleArgument)
+{
+ MacroSnippet aMacro("Sub doUnitTest(argName, argName)\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 d6b2bff6ccc6..6e6c3e024d67 100644
--- a/basic/source/comp/dim.cxx
+++ b/basic/source/comp/dim.cxx
@@ -938,7 +938,14 @@ SbiProcDef* SbiParser::ProcDecl( bool bDecl )
{
pPar->SetParamArray();
}
- pDef->GetParams().Add( pPar );
+ if (SbiSymDef* pOldDef = pDef->GetParams().Find(pPar->GetName(), false))
+ {
+ Error(ERRCODE_BASIC_VAR_DEFINED, pPar->GetName());
+ delete pPar;
+ pPar = pOldDef;
+ }
+ else
+ pDef->GetParams().Add( pPar );
SbiToken eTok = Next();
if( eTok != COMMA && eTok != RPAREN )
{
diff --git a/basic/source/comp/symtbl.cxx b/basic/source/comp/symtbl.cxx
index 5de6be744e6a..b05575adfdfb 100644
--- a/basic/source/comp/symtbl.cxx
+++ b/basic/source/comp/symtbl.cxx
@@ -165,7 +165,7 @@ void SbiSymPool::Add( SbiSymDef* pDef )
}
-SbiSymDef* SbiSymPool::Find( const OUString& rName )
+SbiSymDef* SbiSymPool::Find( const OUString& rName, bool bSearchInParents )
{
sal_uInt16 nCount = m_Data.size();
for( sal_uInt16 i = 0; i < nCount; i++ )
@@ -177,7 +177,7 @@ SbiSymDef* SbiSymPool::Find( const OUString& rName )
return &r;
}
}
- if( pParent )
+ if( bSearchInParents && pParent )
{
return pParent->Find( rName );
}
diff --git a/basic/source/inc/symtbl.hxx b/basic/source/inc/symtbl.hxx
index 629bd6728297..2dfc9c758bda 100644
--- a/basic/source/inc/symtbl.hxx
+++ b/basic/source/inc/symtbl.hxx
@@ -71,7 +71,7 @@ public:
SbiSymDef* AddSym( const OUString& );
SbiProcDef* AddProc( const OUString& );
void Add( SbiSymDef* );
- SbiSymDef* Find( const OUString& ); // variable name
+ SbiSymDef* Find( const OUString&, bool bSearchInParents = true ); // variable name
SbiSymDef* Get( sal_uInt16 ); // find variable per position
SbiSymDef* First(), *Next(); // iterators