Run Basic Macro:
Dim aPropertyValues(0) As New com.sun.star.beans.PropertyValue
ReDim aPropertyValues(5) As com.sun.star.beans.PropertyValue
Result of Msgbox: 0
Version: 18.104.22.168 (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
already reproducible with:
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":
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:
Affected users are encouraged to test the fix and report feedback.