Bug 128218 - FunctionAccess.callFunction returns object type where 'Double' result is expected.
Summary: FunctionAccess.callFunction returns object type where 'Double' result is expe...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
6.1.2.1 release
Hardware: All All
: medium normal
Assignee: Eike Rathke
URL:
Whiteboard: target:6.4.0 target:6.3.4
Keywords: bibisected, bisected, regression
Depends on:
Blocks:
 
Reported: 2019-10-17 16:56 UTC by Wolfgang Jäger
Modified: 2019-10-27 09:05 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wolfgang Jäger 2019-10-17 16:56:20 UTC
The actual version was not listed in the box.
The bug is concerning the API. "Component" might better be "sdk". (Donno)
Example is in BASIC

Version: 6.3.3.1 (x64)
Build ID: f41f4c7f9507aeca13cb9df51f34d80e8ba30a99
CPU threads: 4; OS: Windows 10.0; UI render: default; VCL: win; 
Locale: en-GB (de_DE); UI-Language: en-GB
Calc: CL

Create a new document and a new module in its BASIC standard library. 
Paste 

Sub demo()
fa = createUnoService("com.sun.star.sheet.FunctionAccess")
r  = fa.callFunction("RAND",Array())
Print TypeName(r)
REM r is "Object(0 To 0)" now with r(0)(0) containing the result.
Dim q As Double
q  = fa.callFunction("RAND",Array())
REM Above statement throws an error "Object variable not set".
End Sub

into that module. 
Execute the Sub stepwise and verify the behaviour described by the REM lines.
Comment 1 Wolfgang Jäger 2019-10-17 17:09:07 UTC
As just tested the bug was already present in V 6.1.2.1.
Version field changed.

The youngest version I could test with and which did not show the bug was 6.0.4.2.
Comment 2 Oliver Brinzing 2019-10-19 09:06:07 UTC
confirming

> The youngest version I could test with and which did not 
> show the bug was 6.0.4.2.

btw: works with LO 6.0.7.3 too

but still reproducible with:

Version: 6.4.0.0.alpha1+ (x64)
Build ID: 40b469fdb6dec080a90542935f94d497aa067ef4
CPU threads: 4; OS: Windows 10.0 Build 18362; UI render: default; VCL: win; 
Locale: de-DE (de_DE); UI-Language: en-US
Calc: threaded
Comment 3 Oliver Brinzing 2019-10-19 13:21:22 UTC
that looks like an intended change, started with:

https://gerrit.libreoffice.org/plugins/gitiles/core/+/2dc7a3b7515ffd6181d740aca4ad6e0549ea4a3a

commit	2dc7a3b7515ffd6181d740aca4ad6e0549ea4a3a	[log]
author	Eike Rathke <erack@redhat.com>
Tue Jul 10 15:58:17 2018 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com> 
Fri Jul 13 22:00:45 2018 +0200
tree	f23c859f0338062a38e773db4f3e126bbdfbd9e1
parent	4e4421325d406cc555f15c2b8b5bbab443eb6a7d [diff]

Resolves: tdf#118624 let RAND() in array/matrix mode fill a matrix

... instead of only top left that is referenced for other
elements.

Change-Id: I718946d7e4327b152e2d9f80712395fd7ab67dee
Reviewed-on: https://gerrit.libreoffice.org/57235
Tested-by: Jenkins
Reviewed-by: Eike Rathke <erack@redhat.com>
(cherry picked from commit 8afccbd129ecda81ff00dd2c6e5e10af254ae0ef)
Reviewed-on: https://gerrit.libreoffice.org/57247
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Comment 4 Eike Rathke 2019-10-22 16:25:06 UTC
A tad unfortunate.. callFunction() per default is executed in array mode, you can change that by setting the com.sun.star.sheet.FunctionAccess property IsArrayFunction to false. See https://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1sheet_1_1FunctionAccess.html#a7f24813b5c506f8f0d3eb81f864c741e

Nevertheless, we maybe could let RAND() return a scalar double even in array mode if a 1x1 matrix is hit, for better backwards compatibility.
Comment 5 Wolfgang Jäger 2019-10-22 22:26:21 UTC
(In reply to Eike Rathke from comment #4)
> ...
> you can change that by setting the com.sun.star.sheet.FunctionAccess
> property IsArrayFunction to false. ...

Cannot access this property. It is not shown in the IDE and not listed in the PropertySetInfo of a FunctionAccess object.
Comment 6 Eike Rathke 2019-10-24 15:15:35 UTC
It's an optional property at the service, just try to set it.
Comment 7 Wolfgang Jäger 2019-10-24 16:16:49 UTC
I tried

fa = createUnoService("com.sun.star.sheet.FunctionAccess")
fa.IsArrayFunction = False

but got "Property or method not found: IsArrayFunction."

This was the behaviour with versions 3.3 , 5.4.4, and 6.3.3.1.
Comment 8 Eike Rathke 2019-10-24 21:56:33 UTC
fa.setPropertyValue("IsArrayFunction", False)
Comment 9 Commit Notification 2019-10-25 09:30:50 UTC
Eike Rathke committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/445727d3bce84ef04719242745aac9446035c5bd

Resolves: tdf#128218 Let RAND() return a scalar double instead of a 1x1 matrix

It will be available in 6.4.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.
Comment 10 Eike Rathke 2019-10-25 09:32:39 UTC
Pending review https://gerrit.libreoffice.org/81492 for 6-3
Comment 11 Commit Notification 2019-10-27 09:05:32 UTC
Eike Rathke committed a patch related to this issue.
It has been pushed to "libreoffice-6-3":

https://git.libreoffice.org/core/commit/75c1c58c4ae47dd0bad98dbe95e99d5d3de377de

Resolves: tdf#128218 Let RAND() return a scalar double instead of a 1x1 matrix

It will be available in 6.3.4.

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.