There is a recurring programming error in Basic, when IsMissing is combined by a logical operator with a use of potentially absent variable, as in > If Not IsAbsent(foo) And foo > bar Then ... See e.g. code shown on the screenshot at https://ask.libreoffice.org/t/messagebox-weird-response/86789 We need a comment on IsMissing help page, discussing that this must be > If Not IsAbsent(foo) Then If foo > bar Then ...
Imho, the question is, should Basic support short circuting in boolean expressions or not?
(In reply to Andreas Heinisch from comment #1) I would like to see it in Basic, but this would be an incompatible change, breaking any possible existing code that relies on side effects of unconditional evaluation of all expressions.
How about introducing a new flag like OPTION EXPLICIT? So you have legacy code would be unaffected.
(In reply to Andreas Heinisch from comment #3) This is exactly what is proposed in https://ask.libreoffice.org/t/if-conditions-continue-to-be-evaluated-even-after-the-if-has-been-satisfied/89385/. I am not opposed much, even though it feels like "do it just because we can" ;)
Yep, you are correct. The huge drawback would be that code written with this flag would not work in older versions.
I also believe that the absence of a short circuit must be written in the documentation. May be here: https://help.libreoffice.org/7.6/en-US/text/sbasic/shared/00000002.html?DbPAR=BASIC ?
There are many constructs of this type (except IsMissing), for example: If IsArray(arr) And UBound(arr) >= 1 Then
Here is how Microsoft writes about it in the VBA documentation :) https://learn.microsoft.com/en-us/openspecs/microsoft_general_purpose_programming_languages/ms-vbal/2d70780d-6e99-47d6-9759-2b3a46b8e862
Ah - thanks a lot! Indeed, the operators in Basic combine logical and bit operators - and so, before both sides are evaluated, it's impossible to resolve the result of expression. Hence, the short-circuiting is even impossible generally.
Has this change to disable short-circuiting already been implemented? Because this bug report still says NEW, but when I moved my code from 7.0.5.x to 7.4.7.2 (stable release) it failed in a couple of places. PS: I was scratching my head why my code was failing all of a sudden and went looking into the release notes but google couldn't find anything there. Should it be there? Seems like a major change.
(In reply to Jordi from comment #10) > Has this change to disable short-circuiting already been implemented? This is a misunderstanding. This is not about "change to disable short-circuiting". There was never such a thing in Basic, and that is unchanged. This issue is about mentioning this fact in help; and also, some comments were discussing a prospect of *enabling* short-circuiting, for the first time in the OOo / LO Basic history. If you had some breakage in macros, it is definitely unrelated, and needs own bug reports.