Bug 153142 - IsMissing needs a note about use in conditions (no boolean short-circuit evaluation in Basic)
Summary: IsMissing needs a note about use in conditions (no boolean short-circuit eval...
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Documentation (show other bugs)
(earliest affected)
Hardware: All All
: medium normal
Assignee: Not Assigned
Depends on:
Reported: 2023-01-21 16:00 UTC by Mike Kaganski
Modified: 2023-03-19 16:11 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Note You need to log in before you can comment on or make changes to this bug.
Description Mike Kaganski 2023-01-21 16:00:30 UTC
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 ...
Comment 1 Andreas Heinisch 2023-01-22 08:51:31 UTC
Imho, the question is, should Basic support short circuting in boolean expressions or not?
Comment 2 Mike Kaganski 2023-03-18 21:53:12 UTC
(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.
Comment 3 Andreas Heinisch 2023-03-19 08:14:58 UTC
How about introducing a new flag like OPTION EXPLICIT? So you have legacy code would be unaffected.
Comment 4 Mike Kaganski 2023-03-19 08:23:10 UTC
(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" ;)
Comment 5 Andreas Heinisch 2023-03-19 09:08:33 UTC
Yep, you are correct. The huge drawback would be that code written with this flag would not work in older versions.
Comment 6 Vladimir Sokolinskiy 2023-03-19 14:11:32 UTC
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 
Comment 7 Vladimir Sokolinskiy 2023-03-19 14:18:43 UTC
There are many constructs of this type (except IsMissing), for example:

  If IsArray(arr) And UBound(arr) >= 1 Then
Comment 8 Vladimir Sokolinskiy 2023-03-19 14:29:51 UTC
Here is how Microsoft writes about it in the VBA documentation :)

Comment 9 Mike Kaganski 2023-03-19 16:11:34 UTC
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.