Logical OR operators

This forum is meant for questions and discussions about the X# language and tools
Post Reply
George
Posts: 106
Joined: Thu Nov 05, 2015 9:17 am

Logical OR operators

Post 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
User avatar
Chris
Posts: 4900
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Logical OR operators

Post 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
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Post Reply