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
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.
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
BTW in MS VBA both examples result in error. I believe there's something wrong with the Basic compiler/interpreter in LibreOffice.
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 😞
(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.
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)