summaryrefslogtreecommitdiff
path: root/basic/source
diff options
context:
space:
mode:
authorAndreas Heinisch <andreas.heinisch@yahoo.de>2020-01-27 20:09:05 +0100
committerMike Kaganski <mike.kaganski@collabora.com>2020-03-02 10:08:58 +0100
commit8e323fcacebad1afe9d867b846722a6b9bf20f78 (patch)
tree6a180434e7e08dd6e02af2d6730896bf6ce1e1fe /basic/source
parent6c12de3ed36083f35105dddab6943e5d3693edd8 (diff)
tdf#36737 - Initialize default values of optionals
Initialize default values of optionals in function headers. In LO Basic, optional parameters are allowed, but without any default values. Missing parameters will not be initialized to their respective default values of its datatype, either. With option Compatible, optional parameters are allowed with default values. Missing optional parameters that don't have explicit default values will not be initialized to their default values of its datatype. With option VBASupport, optional parameters are allowed with default values. Missing optional parameters that don't have explicit default values will be initialized to their default values of its datatype. Change-Id: I57aabae5f70d1cf6c4e8feb95ce0db6af753383c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87550 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'basic/source')
-rw-r--r--basic/source/runtime/runtime.cxx39
1 files changed, 18 insertions, 21 deletions
diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx
index bf7501cd4ca9..ffd03f28b7cf 100644
--- a/basic/source/runtime/runtime.cxx
+++ b/basic/source/runtime/runtime.cxx
@@ -4015,11 +4015,18 @@ void SbiRuntime::StepELEM( sal_uInt32 nOp1, sal_uInt32 nOp2 )
PushVar( FindElement( pObj, nOp1, nOp2, ERRCODE_BASIC_NO_METHOD, false ) );
}
-// loading a parameter (+offset+type)
-// If the data type is wrong, create a copy.
-// The data type SbxEMPTY shows that no parameters are given.
-// Get( 0 ) may be EMPTY
+/** Loading of a parameter (+offset+type)
+ If the data type is wrong, create a copy and search for optionals including
+ the default value. The data type SbxEMPTY shows that no parameters are given.
+ Get( 0 ) may be EMPTY
+ @param nOp1
+ the index of the current parameter being processed,
+ where the entry of the index 0 is for the return value.
+
+ @param nOp2
+ the data type of the parameter.
+ */
void SbiRuntime::StepPARAM( sal_uInt32 nOp1, sal_uInt32 nOp2 )
{
sal_uInt16 nIdx = static_cast<sal_uInt16>( nOp1 & 0x7FFF );
@@ -4034,23 +4041,7 @@ void SbiRuntime::StepPARAM( sal_uInt32 nOp1, sal_uInt32 nOp2 )
while( iLoop >= nParamCount )
{
pVar = new SbxVariable();
-
- if( SbiRuntime::isVBAEnabled() &&
- (eType == SbxOBJECT || eType == SbxSTRING) )
- {
- if( eType == SbxOBJECT )
- {
- pVar->PutObject( nullptr );
- }
- else
- {
- pVar->PutString( OUString() );
- }
- }
- else
- {
- pVar->PutErr( 448 ); // like in VB: Error-Code 448 (ERRCODE_BASIC_NAMED_NOT_FOUND)
- }
+ pVar->PutErr( 448 ); // like in VB: Error-Code 448 (ERRCODE_BASIC_NAMED_NOT_FOUND)
refParams->Put32( pVar, iLoop );
iLoop--;
}
@@ -4078,6 +4069,12 @@ void SbiRuntime::StepPARAM( sal_uInt32 nOp1, sal_uInt32 nOp2 )
pVar->PutString( aDefaultStr );
refParams->Put32( pVar, nIdx );
}
+ else if ( SbiRuntime::isVBAEnabled() && eType != SbxVARIANT )
+ {
+ // tdf#36737 - initialize the parameter with the default value of its type
+ pVar = new SbxVariable( pParam->eType );
+ refParams->Put32( pVar, nIdx );
+ }
bOpt = true;
}
}