summaryrefslogtreecommitdiff
path: root/basic
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2019-12-07 17:18:08 +0100
committerXisco Faulí <xiscofauli@libreoffice.org>2019-12-16 13:39:28 +0100
commit9e28127116e35797d373d7d147628a222c7f6ad6 (patch)
treed9109d9fd39df28980f12000c1483831bc89ed3f /basic
parent8525523c926305d134324f16f31c5b10e474808e (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> (cherry picked from commit 0ed214fd8f64eca4f3192b1646595500d772b243) Reviewed-on: https://gerrit.libreoffice.org/84736 Reviewed-by: Xisco Faulí <xiscofauli@libreoffice.org>
Diffstat (limited to 'basic')
-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