Bug 150319 - Calling a non-existing Function should result in error
Summary: Calling a non-existing Function should result in error
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
7.3.5.2 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-08-09 18:40 UTC by Rafael Lima
Modified: 2024-03-18 08:52 UTC (History)
1 user (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 Rafael Lima 2022-08-09 18:40:22 UTC
In Basic, suppose you have a module that contains only the following content:

Sub TestIfFunctionExists
    result = ThisDoesNotExist()
End Sub

If you run the sub above, no error will occur and "result" will have the "Empty" value after the sub finishes.

However, since the function ThisDoesNotExist() does not exist, an error should occur.

The weirdest thing is that running the following Sub will result in an error.

Sub TestIfSubExists
    ThisDoesNotExist()
End Sub

Notice that now ThisDoesNotExist() is being called as a Sub instead of a Function and an error occurs, which is expected.

However, I would expect errors in both cases.

System info

Version: 7.3.5.2 / LibreOffice Community
Build ID: 30(Build:2)
CPU threads: 12; OS: Linux 5.15; UI render: default; VCL: kf5 (cairo+xcb)
Locale: pt-BR (pt_BR.UTF-8); UI: en-US
Ubuntu package version: 1:7.3.5-0ubuntu0.22.04.1
Calc: threaded

Also in

Version: 7.5.0.0.alpha0+ / LibreOffice Community
Build ID: 641d92a73e5b3d0e062e16ed4b42236e1a4796a5
CPU threads: 12; OS: Linux 5.15; UI render: default; VCL: kf5 (cairo+xcb)
Locale: pt-BR (pt_BR.UTF-8); UI: en-US
Calc: threaded
Comment 1 Rafael Lima 2022-08-09 19:11:36 UTC
Apparently this problem only happens when the called function has no parameters. If I try to pass a argument to the non-existing function, an exception is reported by the interpreter.

Sub TestIfFunctionExists_v2
    result = ThisDoesNotExist(a)
End Sub

The code above reports an error. Note that the only difference is that now I'm passing the argument "a" to the non-existing function.
Comment 2 Andreas Heinisch 2022-08-10 08:51:59 UTC
Confirmed in:
Version: 7.0.6.2 (x86)
Build ID: 144abb84a525d8e30c9dbbefa69cbbf2d8d4ae3b
CPU threads: 4; OS: Windows 10.0 Build 18362; UI render: Skia/Raster; VCL: win
Locale: de-DE (de_DE); UI: en-US
Calc: threaded
Comment 3 Rafael Lima 2022-08-10 18:35:41 UTC
BTW in MS VBA both examples result in error.

I believe there's something wrong with the Basic compiler/interpreter in LibreOffice.
Comment 4 Andreas Heinisch 2024-01-24 22:22:36 UTC
Gave it a try:
https://gerrit.libreoffice.org/c/core/+/162487

But it's a pitty that we cannot set an empty parameter list in the expression generator without massive side effects. Even an additional flag is not possible since they are purged using the mask 0x7FFF in the runtime.cxx. Unfortunately the parser cannot decide at compile time because these could be uno or internal objects. 

So no way to tell apart a function/sub from a variable in the expression generator 😞
Comment 5 Rafael Lima 2024-01-25 13:00:11 UTC
(In reply to Andreas Heinisch from comment #4)
> Gave it a try:
> https://gerrit.libreoffice.org/c/core/+/162487

Thanks for the attempt

At least, if one uses "Option Explicit", a runtime error occurs:

Option Explicit

Sub TestIfFunctionExists
    Dim result As Variant
    result = ThisDoesNotExist()
End Sub

This returns the error: "BASIC runtime error. Variable not defined".

IMO using "Option Explicit" is good programming practice.
Comment 6 Andreas Heinisch 2024-01-25 13:56:53 UTC
Yep, but this is a bug too since it uses it as a variable and not as a function or sub (the root cause of this behaviour)