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

            Bug ID: 118544
           Summary: Optional macro parameter defined as Integer has type
                    Variant/String causing type errors in the macro
           Product: LibreOffice
           Version: 4.2.8.2 release
          Hardware: x86-64 (AMD64)
                OS: Linux (All)
            Status: UNCONFIRMED
          Severity: minor
          Priority: medium
         Component: BASIC
          Assignee: libreoffice-bugs@lists.freedesktop.org
          Reporter: bugsinlibreoff...@ecloud-business-solutions.com

Description:
In the macro below, we define the optional parameter 'length' as type Integer
with default value 32.

Yet the msgbox appears saying "Huh - why is length not of type integer????" and
the debugger indicates Variant/String value "32"?

Then we get type error on the following line to calc the value of msb as length
is (somehow?) a Variant/String.

How is this possible?

Option Compatible 'Needed for the default value assignment in the function
definition on the next line
Function BitShiftWithWrapAround(cell as Double,shift As Integer, Optional
length As Integer=32)

    CompatibilityMode(True) 'This line makes no difference
    Dim result as Double

    result = cell

    ' Before the next line executes, debugger shows length as "<missing
parameter>", type String - huh?
    if not (typename(length)="Integer") then
        ' Yet here the type magically becomes Variant/String and the value
suddenly becomes "32" as a string
        msgbox "Huh - why is length not of type integer????"
    end if

    ' Even stranger, now the type suddenly becomes Integer, value 32
    msb = 2^(length-1)

   ' Remainder not included in this bug report- we don't make it past the line
above UNLESS the
   ' if - end if secton immediately above it is included.

   ' To make this function run we need a return value. Just return the msb for
now until this bug is sorted.
   return msb

end Function

Now for the really crazy part - if we remove the section:
  if not typename...
       msgbox ...
  end if

..then we get an LO macro error on the msb = ... line like so:
Inadmissible value or data type.
Data type mismatch.

This is crazy - testing the typename changes the type???? Not testing it
doesn't???

That reeks of side effects.

Steps to Reproduce:
1. Create macro - cut and paste from "Option Compatible" to "end Function"
2. Put a formula in a cell '=BitShiftWithWrapAround(2025167957,-1)'
3. Observe how the msgbox appears, and note the function still works.
4. Remove (or comment out) the 3 lines immediately before msb=
5. Repeat step 2.
6. Observe how an LO Macro error occurs, totally breaking the macro.

Actual Results:
Inadmissible value or data type.
Data type mismatch.

Expected Results:
Function should return 4050335914 (=2025167957 >> 1 with wraparound)

We didn't include the code to do this because we cannot get past the type
mismatch error without including unnecesary code before it, which appears to
produce a side effect.


Reproducible: Always


User Profile Reset: No



Additional Info:
Version: 4.2.8.2
Build ID: 420m0(Build:2)

-- 
You are receiving this mail because:
You are the assignee for the bug.
_______________________________________________
Libreoffice-bugs mailing list
Libreoffice-bugs@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-bugs

Reply via email to