xsharp.eu • Logical OR operators
Page 1 of 1

Logical OR operators

Posted: Wed Aug 01, 2018 2:04 pm
by George
Trying to run a former Vulcan App compiled with X# (with Vulcan RUntime of course), I noticed a difference in Logical OR operators.

My App had the code:

LOCAL aStr AS STRING[]
...
IF aStr <> NULL || aStr:Length < 1
...
ENDIF

The X# runtime error is:
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.

then, I replaced the || with .OR.
IF aStr <> NULL .OR. aStr:Length < 1
...
ENDIF

the error disappeared!

So, if the || operator is used, BOTH conditions are checked.
In contrast, by using the .OR. operator, when the 1st condition is TRUE then the 2nd is ignored.

Is-it the correct operators' behaviour in X#, or the || operator had to behave like the .OR. operator and it's a bug?

regards
George

Logical OR operators

Posted: Thu Aug 02, 2018 1:25 am
by Chris
Hi George,

Yes, this is a compiler bug, apparently the || symbol in this code gets translated to the binary OR operator, instead of the logical OR operator as it should, causing both operands to be evaluated always. And the same bug exists with &&/AND also.

Thanks a lot for reporting this, I think it will be possible to fix this soon.

Chris