basic/qa/basic_coverage/test_date_passed_to_uno.bas      |   48 +++++++++++++++
 basic/qa/basic_coverage/test_variant_arg_used_as_obj.bas |   38 +++++++++++
 basic/source/classes/sbunoobj.cxx                        |    4 -
 basic/source/comp/exprtree.cxx                           |    7 +-
 sc/source/ui/unoobj/funcuno.cxx                          |    2 
 5 files changed, 94 insertions(+), 5 deletions(-)

New commits:
commit f071292a5af10f4718302a1bf9cc9cdc37528225
Author:     Mike Kaganski <[email protected]>
AuthorDate: Thu Jan 23 22:07:29 2025 +0500
Commit:     Mike Kaganski <[email protected]>
CommitDate: Thu Jan 23 20:14:51 2025 +0100

    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 <[email protected]>
    Tested-by: Jenkins

diff --git a/basic/qa/basic_coverage/test_variant_arg_used_as_obj.bas 
b/basic/qa/basic_coverage/test_variant_arg_used_as_obj.bas
new file mode 100644
index 000000000000..41ac139f639d
--- /dev/null
+++ b/basic/qa/basic_coverage/test_variant_arg_used_as_obj.bas
@@ -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
diff --git a/basic/source/comp/exprtree.cxx b/basic/source/comp/exprtree.cxx
index db7254033e5e..2f0316428ce6 100644
--- a/basic/source/comp/exprtree.cxx
+++ b/basic/source/comp/exprtree.cxx
@@ -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
commit 63e7a70ad1a6a8ec4190ab510f683d2fc9dea417
Author:     Mike Kaganski <[email protected]>
AuthorDate: Thu Jan 23 18:09:03 2025 +0500
Commit:     Mike Kaganski <[email protected]>
CommitDate: Thu Jan 23 20:14:46 2025 +0100

    tdf#164811: swap the "if IsCompatibility()" branches to match other places
    
    Commit 9cdb73ff28c4cd6380412468f34ff10e46292a07 (INTEGRATION: CWS jl5vba
    (1.25.94); FILE MERGED, 2004-03-17) has introduced handling of decimal,
    currency, and date for VBASupport mode in sbunoobj.cxx. However, in
    getUnoTypeForSbxBaseType, it changed the behavior for date type in the
    non-VBASupport mode, obviously by mistake. This change swaps the code
    in the 'if' branches, to what appears to be the original intention.
    
    Change-Id: I88cddf7cec1a980f56de96ae1c5e64d8e7630b77
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180637
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>

diff --git a/basic/qa/basic_coverage/test_date_passed_to_uno.bas 
b/basic/qa/basic_coverage/test_date_passed_to_uno.bas
new file mode 100644
index 000000000000..e056ab3b4b4d
--- /dev/null
+++ b/basic/qa/basic_coverage/test_date_passed_to_uno.bas
@@ -0,0 +1,48 @@
+'
+' 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_DatePassedToUno
+    doUnitTest = TestUtil.GetResult()
+End Function
+
+Sub verify_DatePassedToUno
+    On Error GoTo errorHandler
+
+    ' Given a date variable, and passing it to an UNO interface method (i.e., 
going through
+    ' the Basic-to-UNO conversion), in the absence of VBASupport mode, the 
date value must
+    ' be converted to a number, not to a struct / empty interface
+    Dim aDate as Date
+    aDate = #2025-01-23T12:00#
+
+    Dim aUnoObject as Object
+    aUnoObject = CreateUnoListener("XTypeConverter_", 
"com.sun.star.script.XTypeConverter")
+
+    Dim aConvResult
+    ' Without the fix, the following line would fail, triggering errorHandler 
reporting
+    ' "91: Object variable not set."
+    aConvResult = aUnoObject.convertToSimpleType(aDate, 
com.sun.star.uno.TypeClass.STRING)
+    ' If 'Option VBASupport 1' were used, the following line would fail with 
"Wrong input
+    ' type: Date", because the value would be marshalled using 
oleautomation::Date struct
+    TestUtil.AssertEqualStrict(aConvResult, "45680.5", "aConvResult")
+
+    Exit Sub
+errorHandler:
+    TestUtil.ReportErrorHandler("verify_DatePassedToUno", Err, Error$, Erl)
+End Sub
+
+Function XTypeConverter_convertToSimpleType(aFrom, aDestinationType)
+    If IsNumeric(aFrom) Then
+        XTypeConverter_convertToSimpleType = CStr(aFrom)
+    Else
+        XTypeConverter_convertToSimpleType = "Wrong input type: " & 
TypeName(aFrom)
+    End If
+End Function
diff --git a/basic/source/classes/sbunoobj.cxx 
b/basic/source/classes/sbunoobj.cxx
index 25a395e7a6bf..871e02e76f1f 100644
--- a/basic/source/classes/sbunoobj.cxx
+++ b/basic/source/classes/sbunoobj.cxx
@@ -831,9 +831,9 @@ static Type getUnoTypeForSbxBaseType( SbxDataType eType )
         case SbxDATE:       {
                             SbiInstance* pInst = GetSbData()->pInst;
                             if( pInst && pInst->IsCompatibility() )
-                                aRetType = cppu::UnoType<double>::get();
-                            else
                                 aRetType = 
cppu::UnoType<oleautomation::Date>::get();
+                            else
+                                aRetType = cppu::UnoType<double>::get();
                             }
                             break;
         case SbxSTRING:     aRetType = cppu::UnoType<OUString>::get(); break;
commit 073022ec122e75931395d6f25de2d19ffbac058e
Author:     Mike Kaganski <[email protected]>
AuthorDate: Thu Jan 23 18:01:23 2025 +0500
Commit:     Mike Kaganski <[email protected]>
CommitDate: Thu Jan 23 20:14:40 2025 +0100

    Avoid matching the 'if' with an empty reference
    
    Commit d833992e7e06f7d385fca6ffe35ce66b79360a63  (Avoid checking
    exact interface type of Any value,  2024-11-08)  had modified an
    'if' condition in ScFunctionAccess::callFunction, so an Any with
    a reference  to an object  implementing  the requested interface
    could be matched, even if the Any points to another interface of
    the object. However, it made an empty XInterface reference match,
    too, which is unexpected.
    
    It is not a real problem now:  both no match,  and a match of an
    empty reference  set the error;  but in the future,  a new "else"
    branch could be added  after this one,  and then it could behave
    unexpectedly, so fix it here.
    
    Change-Id: I43375fc34fe01665e7984ea6ad7052f7969c13c0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180636
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>

diff --git a/sc/source/ui/unoobj/funcuno.cxx b/sc/source/ui/unoobj/funcuno.cxx
index 82ad1eeab815..7e301b4b3984 100644
--- a/sc/source/ui/unoobj/funcuno.cxx
+++ b/sc/source/ui/unoobj/funcuno.cxx
@@ -581,7 +581,7 @@ uno::Any SAL_CALL ScFunctionAccess::callFunction( const 
OUString& aName,
         {
             ArrayOfArrayProc<uno::Any>::processSequences( pDoc, rArg, 
aTokenArr, nDocRow, bArgErr, bOverflow );
         }
-        else if (uno::Reference<table::XCellRange> xRange; rArg >>= xRange)
+        else if (uno::Reference<table::XCellRange> xRange; (rArg >>= xRange) 
&& xRange)
         {
             // currently, only our own cell ranges are supported
 

Reply via email to