Run Basic Macro: Sub RunRedim Dim aPropertyValues(0) As New com.sun.star.beans.PropertyValue ReDim aPropertyValues(5) As com.sun.star.beans.PropertyValue Msgbox Ubound(aPropertyValues) End Sub Result of Msgbox: 0 Expected: 5 Version: 7.0.1.2 (x64) Build ID: 7cbcfc562f6eb6708b5ff7d7397325de9e764452 CPU threads: 6; OS: Windows 10.0 Build 18363; UI render: default; VCL: win Locale: ru-RU (ru_RU); ИП: ru-RU Calc: threaded
already reproducible with: LibreOffice 3.3.0 OOO330m19 (Build:6) tag libreoffice-3.3.0.4
Some observations: In https://opengrok.libreoffice.org/xref/core/basic/source/runtime/runtime.cxx?r=d84deb95#3870 the information about the array dimension is lost and then it cannot be redimensioned in https://opengrok.libreoffice.org/xref/core/basic/source/runtime/runtime.cxx?r=d84deb95#2151. After I re-added the parameters, the array will get the new dimensions, and the new objects for the redimensioned array will be created in https://opengrok.libreoffice.org/xref/core/basic/source/runtime/runtime.cxx?r=d84deb95#4440. However, the old array somehow survives in the expression stack and will be read for the UBound function, leading to the error.
Some additional findings: The script does indeed work with ReDim Preserve, where the only additional command generated by the compiler is StepREDIMP_ERASE and DCREATE_REDIMP_ instead of DCREATE_. Atm, SbiRuntime::StepDCREATE and SbiRuntime::StepDCREATE_REDIMP are the same. At runtime, the function SbiRuntime::StepREDIMP_ERASE copies a reference to the array and reuses it in SbiRuntime::CheckArray, where it prevents the retrieval of a new array element using the old reference. Without Preserve, the first element of the array will be passed as an argument, leading to missing dimensions in SbiRuntime::DimImpl. However, I don't know how to retrieve the correct variable SbiRuntime::CheckArray without breaking additional functionalities.
Andreas Heinisch committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/0426748927919dbfd4cf5c0bb904e21a90d6c9d7 tdf#136755, tdf#124008 - delete the variable beforehand REDIM It will be available in 7.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.