Bug 160578 - BASIC Runtime error. Object variable not set. Happens when the argument of sub procedure is not an object
Summary: BASIC Runtime error. Object variable not set. Happens when the argument of su...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium normal
Assignee: Mike Kaganski
URL:
Whiteboard: target:25.8.0 target:25.2.1
Keywords:
Depends on:
Blocks:
 
Reported: 2024-04-07 15:08 UTC by Jean-Pierre Sanchez
Modified: 2025-01-23 21:36 UTC (History)
3 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 Jean-Pierre Sanchez 2024-04-07 15:08:11 UTC
Description:
An unexpected runtime error when the argument of a sub procedure is a Variant that can be an object or not. 

Steps to Reproduce:
Sub Main
	Test("One")
End Sub

Sub Test(pvArg As Variant)
	On Local Error GoTo Erreur
	If IsObject(pvArg) then
		Print pvArg.SupportsService("com.sun.star.table.Cell")
	Else
		Print "pvArg is not an object"
	EndIf
	Exit Sub
Erreur: Print "Error"
End Sub

Actual Results:
Raises a runtime error on the first line of the sub procedure.
The 'On Local Error instruction' is ignored

Expected Results:
No runtime error. The argument should be tested by IsObject.


Reproducible: Always


User Profile Reset: No

Additional Info:
[Information automatically included from LibreOffice]
Locale: en-US
Module: BasicIDE
[Information guessed from browser]
OS: Mac OS X (All)
OS is 64bit: no
Comment 1 Robert Großkopf 2024-04-12 19:00:10 UTC
You couldn't print
pvArg.SupportsService("com.sun.star.table.Cell")

You could print "Object" instead.
Comment 2 Buovjaga 2024-07-22 07:29:24 UTC
With your example, the Local Error is triggered. It seems the example is incomplete and not testable by others.

If I comment out

On Local Error GoTo Erreur

I get

BASIC runtime error.
Argument is not optional.

pointing to line

If IsObject(pvArg) then

Please advise.

Arch Linux 64-bit
Version: 25.2.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 180f0c1ec8e195043b5f4298737a219026a8b944
CPU threads: 8; OS: Linux 6.9; UI render: default; VCL: kf6 (cairo+wayland)
Locale: fi-FI (fi_FI.UTF-8); UI: en-US
Calc: CL threaded
Built on 22 July 2024
Comment 3 QA Administrators 2025-01-19 03:10:39 UTC
Dear Jean-Pierre Sanchez,

This bug has been in NEEDINFO status with no change for at least
6 months. Please provide the requested information as soon as
possible and mark the bug as UNCONFIRMED. Due to regular bug
tracker maintenance, if the bug is still in NEEDINFO status with
no change in 30 days the QA team will close the bug as INSUFFICIENTDATA
due to lack of needed information.

For more information about our NEEDINFO policy please read the
wiki located here:
https://wiki.documentfoundation.org/QA/Bugzilla/Fields/Status/NEEDINFO

If you have already provided the requested information, please
mark the bug as UNCONFIRMED so that the QA team knows that the
bug is ready to be confirmed.
 
Thank you for helping us make LibreOffice even better for everyone!

Warm Regards,
QA Team

MassPing-NeedInfo-Ping
Comment 4 Mike Kaganski 2025-01-23 09:03:01 UTC
(In reply to Buovjaga from comment #2)
> Please advise.

It looks like you are trying to run 'Test', instead of 'Main' that calls 'Test'.
Comment 5 Buovjaga 2025-01-23 09:11:43 UTC
(In reply to Mike Kaganski from comment #4)
> (In reply to Buovjaga from comment #2)
> > Please advise.
> 
> It looks like you are trying to run 'Test', instead of 'Main' that calls
> 'Test'.

Thanks, then I repro.

Arch Linux 64-bit
Version: 24.8.4.2 (X86_64) / LibreOffice Community
Build ID: 480(Build:2)
CPU threads: 8; OS: Linux 6.12; UI render: default; VCL: kf6 (cairo+wayland)
Locale: fi-FI (fi_FI.UTF-8); UI: en-US
24.8.4-1
Calc: threaded
Comment 6 Buovjaga 2025-01-23 09:35:11 UTC
Already in 7.0.
Comment 7 Mike Kaganski 2025-01-23 11:14:24 UTC
Note that the problem is the line

		Print pvArg.SupportsService("com.sun.star.table.Cell")

commenting that line out makes it work.
Comment 8 Mike Kaganski 2025-01-23 13:22:12 UTC
Already in OOo 2.2.0.
Comment 9 Mike Kaganski 2025-01-23 17:48:03 UTC
https://gerrit.libreoffice.org/c/core/+/180665
Comment 10 Commit Notification 2025-01-23 19:15:52 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/f071292a5af10f4718302a1bf9cc9cdc37528225

tdf#160578: do not modify procedure argument type based on its use

It will be available in 25.8.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 11 Commit Notification 2025-01-23 21:36:14 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "libreoffice-25-2":

https://git.libreoffice.org/core/commit/ba0a55592a93de3f22888dc49b74509fd1d8f08c

tdf#160578: do not modify procedure argument type based on its use

It will be available in 25.2.1.

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.