1.Run the next Basic script. Sub Test1 Dim i As Long, arr arr=IIf(i=0, Array(), Array(0)) End Sub An error occurs that must not occur. 2.Run the next Basic script. Sub Test2 Dim i As Long, arr arr=IIf(i=1, Array(), Array(0)) Msgbox IsArray(arr) End Sub Returns False, must be True.
I can reproduce the error in LO 7.3. I also tried the following variation: Sub TestA Dim i as Long, arr, a, b i = 0 a = Array() b = Array(0) arr = Iif(i = 0, a, b) End Sub Which returned the error "Inadmissible value or data type. Index out of defined range." This does not seem to make sense since we're not trying to access internal data of the array. This issue has something to do with the Array object. The following code runs without issues: Sub TestB Dim i as Long, arr, a, b i = 0 a = 3 b = 4 arr = Iif(i = 0, a, b) End Sub System info: Version: 7.3.3.2 / LibreOffice Community Build ID: 30(Build:2) CPU threads: 12; OS: Linux 5.13; UI render: default; VCL: kf5 (cairo+xcb) Locale: pt-BR (pt_BR.UTF-8); UI: en-US Ubuntu package version: 1:7.3.3~rc2-0ubuntu0.21.10.1~lo1 Calc: threaded
Already in 6.0.0.3.
It seems that IIF evaluate both values before give a return value. In PitonYack pag 77 : "The IIf (“Immediate If”) function returns one of two values based on a conditional expression.". May be array is not a valid value. Workaround : Sub TestA Dim i as Long, arr, a, b i = 0 a = Array() b = Array(0) arr = b : If i = 0 Then arr = a ' arr = Iif(i = 0, a, b) End Sub
The following line raises an error arr = Iif(True, Array("A","B"), Array("B","A")) ' Raises an error The following line does not work properly: arr = "A" arr = Iif(False, Array("A","B"), Array("B","A")) ' IIF exposes the same issue when with functions returning an Array Sub Main arr = Iif(true, getArray1(), getArray2()) End Sub Function getArray1() As Variant arr = Array("A","B") getArray1 = arr End Function Function getArray2() As Variant arr = Array("B","A") getArray2 = arr End Function
I tried this code Sub Test_NoError Dim arr2 As Variant arr2 = Iif(false, getArray(), getArray()) End Sub Sub Test_Error Dim arr2 As Variant arr2 = Iif(true, getArray(), getArray()) End Sub Function getArray() As Variant Dim arr As Variant arr = Array("A","B") getArray = arr End Function with the same results (invocation with "true" - error, with "false" - no error). Next, I changed SbRtl_Iif function (see https://opengrok.libreoffice.org/xref/core/basic/source/runtime/methods1.cxx?r=b710ba48503372ddaf10a17ce7f4f3340bc8adb8#405 ) into void SbRtl_Iif(StarBASIC*, SbxArray& rPar, bool) { if (rPar.Count() != 4) return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT); *rPar.Get(0) = *rPar.Get(2); } so that first argument of "iif" doesn't matter... Or does it? The results are still the same. Despite the fact that the modified function doesn't check if the "iif" function was called with true or false, the results are still the same. So, the error occurs or not even when the paths of SbRtl_Iif execution are the same. It only depends on whether "iif" was called with true or false. The same happens with function: void SbRtl_Iif(StarBASIC*, SbxArray& rPar, bool) { if (rPar.Count() != 4) return StarBASIC::Error(ERRCODE_BASIC_BAD_ARGUMENT); *rPar.Get(0) = *rPar.Get(3); } What do you think?
Version: 26.2.0.0.alpha0+ (X86_64) / LibreOffice Community Build ID: c0c3d93e577d24085663bcb1a62596bc5ab7e678 CPU threads: 4; OS: Windows 10 X86_64 (build 19045); UI render: Skia/Vulkan; VCL: win Locale: pl-PL (pl_PL); UI: en-US Calc: threaded
https://gerrit.libreoffice.org/c/core/+/187145
Mike Kaganski committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/99247bfc4e42652baddf606f90e31fb4d22006ab tdf#149151: disambiguate method parameters and array indexes It will be available in 26.2.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Mike, thank you very much for fixing the bug!
Mike Kaganski committed a patch related to this issue. It has been pushed to "libreoffice-25-8": https://git.libreoffice.org/core/commit/a7e4d70072314957fd3484251f3775099097cd2a tdf#149151: disambiguate method parameters and array indexes It will be available in 25.8.0.0.beta2. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.