tdf#131818 BASIC: Fix optional array parameters in VBA
Update parser to reject optional array parameters in VBA mode. Change-Id: Ibf5c47d9d6e0e272f4d21ed18ccba769e542aac3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/203437 Tested-by: Jenkins Reviewed-by: Neil Roberts <nroberts@libreoffice.org>
This commit is contained in:
@@ -285,4 +285,15 @@ CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testMissingEndIf)
|
||||
}
|
||||
}
|
||||
|
||||
CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testVbaOptionalArrayParameterIsSyntaxError)
|
||||
{
|
||||
MacroSnippet aMacro(u"Option VBASupport 1\n"
|
||||
"Function doUnitTest(Optional A() As Integer) As Integer\n"
|
||||
" doUnitTest = 0\n"
|
||||
"End Function\n"_ustr);
|
||||
aMacro.Compile();
|
||||
CPPUNIT_ASSERT(aMacro.HasError());
|
||||
CPPUNIT_ASSERT_EQUAL(ERRCODE_BASIC_SYNTAX, aMacro.getError().GetCode());
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|
||||
|
||||
@@ -106,14 +106,14 @@ Sub verify_testIsMissingVba()
|
||||
' TestUtil.AssertEqual(TestOptArray(), IsMissingAB, "TestOptArray()")
|
||||
' TestUtil.AssertEqual(TestOptArray(aA), IsMissingB, "TestOptArray(A)")
|
||||
' TestUtil.AssertEqual(TestOptArray(, aB), IsMissingA, "TestOptArray(, B)")
|
||||
TestUtil.AssertEqual(TestOptArray(aA, aB), IsMissingNone, "TestOptArray(A, B)")
|
||||
' TestUtil.AssertEqual(TestOptArray(aA, aB), IsMissingNone, "TestOptArray(A, B)")
|
||||
|
||||
' optionals with array datatypes (ByRef and ByVal)
|
||||
' TODO - New bug report? Scanner initializes variable not as an array
|
||||
' TestUtil.AssertEqual(TestOptArrayByRefByVal(), IsMissingAB, "TestOptArrayByRefByVal()")
|
||||
' TestUtil.AssertEqual(TestOptArrayByRefByVal(aA), IsMissingB, "TestOptArrayByRefByVal(A)")
|
||||
' TestUtil.AssertEqual(TestOptArrayByRefByVal(, aB), IsMissingA, "TestOptArrayByRefByVal(, B)")
|
||||
TestUtil.AssertEqual(TestOptArrayByRefByVal(aA, aB), IsMissingNone, "TestOptArrayByRefByVal(A, B)")
|
||||
' TestUtil.AssertEqual(TestOptArrayByRefByVal(aA, aB), IsMissingNone, "TestOptArrayByRefByVal(A, B)")
|
||||
|
||||
' tdf#143706 - optionals with named arguments (:= syntax)
|
||||
' Without the fix in place, this test would have failed with:
|
||||
@@ -169,14 +169,6 @@ Function TestOptObjectByRefByVal(Optional ByRef A As Collection, Optional ByVal
|
||||
TestOptObjectByRefByVal = WhatIsMissing(IsNull(A), IsNull(B))
|
||||
End Function
|
||||
|
||||
Function TestOptArray(Optional A() As Integer, Optional B() As Variant)
|
||||
TestOptArray = WhatIsMissing(IsEmpty(A), IsEmpty(B))
|
||||
End Function
|
||||
|
||||
Function TestOptArrayByRefByVal(Optional ByRef A() As Integer, Optional ByVal B() As Variant)
|
||||
TestOptArrayByRefByVal = WhatIsMissing(IsEmpty(A), IsEmpty(B))
|
||||
End Function
|
||||
|
||||
Function WhatIsMissing(is_missingA, is_missingB)
|
||||
If is_missingA And is_missingB Then
|
||||
WhatIsMissing = IsMissingAB
|
||||
|
||||
@@ -99,14 +99,14 @@ Sub verify_testOptionalsVba()
|
||||
' TestUtil.AssertEqual(TestOptArray(), 0, "TestOptArray()")
|
||||
' TestUtil.AssertEqual(TestOptArray(aA), 579, "TestOptArray(A)")
|
||||
' TestUtil.AssertEqualApprox(TestOptArray(, aB), 691.2, 1E-5, "TestOptArray(, B)")
|
||||
TestUtil.AssertEqualApprox(TestOptArray(aA, aB), 1270.2, 1E-5, "TestOptArray(A, B)")
|
||||
' TestUtil.AssertEqualApprox(TestOptArray(aA, aB), 1270.2, 1E-5, "TestOptArray(A, B)")
|
||||
|
||||
' optionals with array datatypes (ByRef and ByVal)
|
||||
' TODO - New bug report? Scanner initializes variable not as an array
|
||||
' TestUtil.AssertEqual(TestOptArrayByRefByVal(), 0, "TestOptArrayByRefByVal()")
|
||||
' TestUtil.AssertEqual(TestOptArrayByRefByVal(aA), 579, "TestOptArrayByRefByVal(A)")
|
||||
' TestUtil.AssertEqualApprox(TestOptArrayByRefByVal(, aB), 691.2, 1E-5, "TestOptArrayByRefByVal(, B)")
|
||||
TestUtil.AssertEqualApprox(TestOptArrayByRefByVal(aA, aB), 1270.2, 1E-5, "TestOptArrayByRefByVal(A, B)")
|
||||
' TestUtil.AssertEqualApprox(TestOptArrayByRefByVal(aA, aB), 1270.2, 1E-5, "TestOptArrayByRefByVal(A, B)")
|
||||
|
||||
' tdf#143707 - check correct initialization of default value for optionals
|
||||
' Without the fix in place, this test would have failed with
|
||||
@@ -169,14 +169,6 @@ Function TestOptObjectByRefByVal(Optional ByRef A As Collection, Optional ByVal
|
||||
If Not IsNull(B) Then TestOptObjectByRefByVal = TestOptObjectByRefByVal + CollectionSum(B)
|
||||
End Function
|
||||
|
||||
Function TestOptArray(Optional A() As Integer, Optional B() As Variant)
|
||||
TestOptArray = ArraySum(IsMissing(A), A) + ArraySum(IsMissing(B), B)
|
||||
End Function
|
||||
|
||||
Function TestOptArrayByRefByVal(Optional ByRef A() As Integer, Optional ByVal B() As Variant)
|
||||
TestOptArrayByRefByVal = ArraySum(IsMissing(A), A) + ArraySum(IsMissing(B), B)
|
||||
End Function
|
||||
|
||||
Function OptNumberSum(is_missingA As Boolean, A, is_missingB As Boolean, B)
|
||||
OptNumberSum = 0
|
||||
If Not is_missingA Then OptNumberSum = A
|
||||
|
||||
@@ -961,6 +961,12 @@ SbiProcDef* SbiParser::ProcDecl( bool bDecl )
|
||||
{
|
||||
break;
|
||||
}
|
||||
if( bVBASupportOn && bOptional && pPar->IsWithBrackets() )
|
||||
{
|
||||
Error( ERRCODE_BASIC_SYNTAX );
|
||||
delete pPar;
|
||||
break;
|
||||
}
|
||||
if( bByVal )
|
||||
{
|
||||
pPar->SetByVal(true);
|
||||
|
||||
Reference in New Issue
Block a user