fbpx

Logical OR operators

  • George Theopoulos
  • George Theopoulos's Avatar Topic Author
  • Offline
More
5 months 2 weeks ago #1 by George Theopoulos
Logical OR operators was created by George Theopoulos
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

Please Log in or Create an account to join the conversation.

More
5 months 2 weeks ago #2 by Chris Pyrgas
Replied by Chris Pyrgas on topic Logical OR operators
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

XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.