https://bugs.documentfoundation.org/show_bug.cgi?id=145570

            Bug ID: 145570
           Summary: ReDim spills out of scope
           Product: LibreOffice
           Version: 7.2.2.2 release
          Hardware: x86-64 (AMD64)
                OS: Linux (All)
            Status: UNCONFIRMED
          Severity: normal
          Priority: medium
         Component: Calc
          Assignee: [email protected]
          Reporter: [email protected]

If you pass a Variant holding an array to a Function normally you may access
that array by its parameter name, as expected, regardless of array dimension
count. However, if you ReDim that parameter name with different dimension count
even in an excluded code branch, BEFORE attempting to access the array, the
access to the array under the passed dimension count will not compile.

The example below will not compile.

Sub StartBug()
        Dim A(1 To 2, 1 To 2)
        FuncBug(A)
End Sub
Function FuncBug(A As Variant)
        If False Then
                ReDim A(1 To 3)
        Else
                A(1,1) = 42
        End If
End Function

This next example below will compile.

Sub StartBug()
        Dim A(1 To 2, 1 To 2)
        FuncBug(A)
End Sub
Function FuncBug(A As Variant)
        If True Then
                A(1,1) = 42
        Else
                ReDim A(1 To 3)
        End If
End Function

Simply put, the compiler seems--I mean seems, not is--naive when protecting
against dimension count errors.

There would seem to be a heartier workaround than ordering of the branches by
Dimming and ReDimming an array locally to FuncBug then assigning that back to A
before exit, but this bug might relate to Bug 133811 and seems worth
consideration.

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to