tdf#160578: do not modify procedure argument type based on its use
Since the initial import, there is a code in SbiExpression::Term, that checks if the defined symbol is used as object (e.g., dot notation to access its members), and then, if its defined type is Variant, then it is corrected to Object. There is no rationale for this in comments; so I have no way to know what could break if that core is dropped. It's obvious that at least for procedure arguments, such correction is wrong: the argument definition is the procedure's API; and the actual use of the symbol should not unexpectedly change what is advertised. This change limits the application of the correction to non-arguments. If it should be dropped completely is a separate question. Change-Id: Ia902afa3f744d0d51510ba6903be45f78e2f6429 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180665 Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Tested-by: Jenkins
This commit is contained in:
38
basic/qa/basic_coverage/test_variant_arg_used_as_obj.bas
Normal file
38
basic/qa/basic_coverage/test_variant_arg_used_as_obj.bas
Normal file
@@ -0,0 +1,38 @@
|
||||
'
|
||||
' 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/.
|
||||
'
|
||||
|
||||
Option Explicit
|
||||
|
||||
Function doUnitTest() As String
|
||||
TestUtil.TestInit
|
||||
verify_VariantArgUsedAsObj
|
||||
doUnitTest = TestUtil.GetResult()
|
||||
End Function
|
||||
|
||||
Sub verify_VariantArgUsedAsObj
|
||||
On Error GoTo errorHandler
|
||||
|
||||
Dim aResult
|
||||
' Without the fix, the following line would fail, triggering errorHandler reporting
|
||||
' "91: Object variable not set."
|
||||
aResult = aFuncWithVarArg(0)
|
||||
TestUtil.AssertEqualStrict(aResult, "Integer", "aResult")
|
||||
|
||||
Exit Sub
|
||||
errorHandler:
|
||||
TestUtil.ReportErrorHandler("verify_VariantArgUsedAsObj", Err, Error$, Erl)
|
||||
End Sub
|
||||
|
||||
Function aFuncWithVarArg(arg)
|
||||
' The 'arg' is implicitly Variant; and its following use as object (after a check),
|
||||
' i.e. accessing its method using dot notation, must not change the declaration type
|
||||
If IsObject(arg) Then
|
||||
arg.some_func()
|
||||
End If
|
||||
aFuncWithVarArg = TypeName(arg)
|
||||
End Function
|
@@ -333,7 +333,9 @@ std::unique_ptr<SbiExprNode> SbiExpression::Term( const KeywordSymbolInfo* pKeyw
|
||||
// from 16.12.95 (similar cases possible perhaps?!?)
|
||||
if( eType == SbxOBJECT && pDef->GetType() == SbxVARIANT )
|
||||
{
|
||||
pDef->SetType( SbxOBJECT );
|
||||
// Do not modify the type of procedure arguments
|
||||
if (pDef->GetScope() != SbPARAM)
|
||||
pDef->SetType(SbxOBJECT);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -352,7 +354,8 @@ std::unique_ptr<SbiExprNode> SbiExpression::Term( const KeywordSymbolInfo* pKeyw
|
||||
if( bObj )
|
||||
{
|
||||
// from 8.1.95: Object may also be of the type SbxVARIANT
|
||||
if( pDef->GetType() == SbxVARIANT )
|
||||
// (but do not modify type of procedure arguments)
|
||||
if (pDef->GetType() == SbxVARIANT && pDef->GetScope() != SbPARAM)
|
||||
pDef->SetType( SbxOBJECT );
|
||||
// if we scan something with point,
|
||||
// the type must be SbxOBJECT
|
||||
|
Reference in New Issue
Block a user