Description: Iif(condition, expression1, expression2) evaluates BOTH expressions before execution. Exceptions can be raised unconditionnally. e.g. Sub _inverse_ Print Iif(x=0,0,1/x) End Sub Steps to Reproduce: 1. Copy _inverse_ example routine 2. Run it 3. Observe the result Actual Results: "Division by zero" error is thrown Expected Results: Warning "0" should appear Reproducible: Always User Profile Reset: No Additional Info: Expected behaviour is obtained with libO 6.1.2
I thought SbRtl_Iif could be a start point but it's not even called. I don't know where "Iif" is dealt in LO and above all how to find the location. (git grep -in iif didn't return anything interesting).
At this line, the execution of the macro starts: https://opengrok.libreoffice.org/xref/core/basic/source/runtime/runtime.cxx?r=781b6ac9#788 and the error occurs in https://opengrok.libreoffice.org/xref/core/basic/source/runtime/runtime.cxx?r=781b6ac9#1375 because both expressions are evaluated before Iif is called.
(In reply to Andreas Heinisch from comment #2) > At this line, the execution of the macro starts: > https://opengrok.libreoffice.org/xref/core/basic/source/runtime/runtime. > cxx?r=781b6ac9#788 and the error occurs in > https://opengrok.libreoffice.org/xref/core/basic/source/runtime/runtime. > cxx?r=781b6ac9#1375 because both expressions are evaluated before Iif is > called. Ok but where is "iif" in these locations?
The problem is that variable "x" is called from the stack and BEFORE the function Iif is called all the steps in that line are performed, leading to a division by zero error. Therefore, Iif is never called.
(In reply to Andreas Heinisch from comment #4) > The problem is that variable "x" is called from the stack and BEFORE the > function Iif is called all the steps in that line are performed, leading to > a division by zero error. Therefore, Iif is never called. Ok I had missed the "before". Thank you for your patience.
You are welcome. I am glad that I could help.
(In reply to Alain Romedenne from comment #0) > Description: > Iif(condition, expression1, expression2) evaluates BOTH expressions before > execution. Exceptions can be raised unconditionnally. I don't think this is a regression. In fact, I don't think it's a bug, I haven't found a reference to StarBasic, but VBA has the same function: https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/iif-function This states: "IIf always evaluates both truepart and falsepart, even though it returns only one of them. Because of this, you should watch for undesirable side effects. For example, if evaluating falsepart results in a division by zero error, an error occurs even if expr is True." Further note on the change that happened in 6.3: > e.g. > Sub _inverse_ > Print Iif(x=0,0,1/x) > End Sub If you do it like this, there's been a division by zero in older versions as well: x=0 Print Iif(x=0,0,1/x) The difference in the evaluation of the original sample came with the following commit: https://cgit.freedesktop.org/libreoffice/core/commit/?id=15c39bb2e75df40c30bcbf789d815376dd2e31ce author Eike Rathke <erack@redhat.com> 2019-05-02 20:54:16 +0200 committer Eike Rathke <erack@redhat.com> 2019-05-02 22:35:35 +0200 Resolves: tdf#124605 ditch "if operand 1 is Empty, result is operand 2"