<html>
    <head>
      <base href="https://bugs.documentfoundation.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_UNCONFIRMED "
   title="UNCONFIRMED - Invoking a Basic routine with ByRef Variant parameter returns wrong value type"
   href="https://bugs.documentfoundation.org/show_bug.cgi?id=133887">133887</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Invoking a Basic routine with ByRef Variant parameter returns wrong value type
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>LibreOffice
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>Inherited From OOo
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>UNCONFIRMED
          </td>
        </tr>

        <tr>
          <th>Keywords</th>
          <td>difficultyBeginner, easyHack, skillCpp
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>medium
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>BASIC
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>libreoffice-bugs@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>mikekaganski@hotmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>andreas.heinisch@yahoo.de
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="http://bugs.documentfoundation.org/attachment.cgi?id=161869" name="attach_161869" title="A test document with macros">attachment 161869</a> <a href="http://bugs.documentfoundation.org/attachment.cgi?id=161869&action=edit" title="A test document with macros">[details]</a></span>
A test document with macros

This is one of two related bug reports (the other is to follow); the attached
test document contains the tests for both. Please run TestByRefFromInvoke, and
only check first line of output for the purposes of this bug.

If there is a routine with a ByRef (default) parameter (i.e., inout parameter),
invoking it using XScript::invoke [1] requires passing *in* values through the
first array (sequence), and getting their modified *out* values in the last
passed array:

<span class="quote">> Sub Foo(v) ' default ByRef As Variant
>     v = 6.75
> End Sub</span >

<span class="quote">> Sub TestInvoke
>     oScript = thisComponent.getScriptProvider().getScript("vnd.sun.star.script:Standard.Module1.Foo?language=Basic&location=document")
>     oScript.invoke(Array(0), aOutInd, aOutArr)
>     MsgBox aOutArr(0)
> End Sub</span >

TestInvoke above passes "0" as initial value of the variable passed to the Foo,
and expects to get the modified value in the aOutArr(0) - i.e., it should
output "6.75".

However, the actual returned value is 7 - i.e., the result is converted to an
integral type. It is possible to get the correct result by modifying the value
passed to invoke call like this:

<span class="quote">>     oScript.invoke(Array(0.1), aOutInd, aOutArr)</span >

I.e., the type of returned value depends on the passed value. Passing an
integer value result in integer, Passing a string would result in "6.75"
returned as string...

The problem was introduced in
<a href="https://git.libreoffice.org/core/+/2115a3492c5b73f6a3666761a0290d5511d8091e">https://git.libreoffice.org/core/+/2115a3492c5b73f6a3666761a0290d5511d8091e</a> for
i#66055, where passed variables made fixed to enable correct ByRef handling of
arguments with explicit integral types. However, this means that when we pass
an Integer to the code, its type is fixed at this point, and later the
assignment of a value of a different type converts the type to the original
fixed type.

The introduced code in practice made the variable fixed unconditionally, since
unoToSbxValue does not return an SbxVARIANT.

The OOo bug report referred to SbiRuntime::SetParameters; and the latter checks
not only the type of the passed value for being SbxVARIANT, but also the type
of the parameter of the method. So we should extend the mentioned OOo bug fix
to do the same in the BasicScriptImpl::invoke: get the type of variable; then
if we have pInfo, and it returns valid 
param info for this param, we should get the type of the param instead; and
only then, if the resulting type is not SbxVARIANT, we should set the "fixed"
flag.

[1]
<a href="https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1script_1_1provider_1_1XScript.html">https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1script_1_1provider_1_1XScript.html</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>