G'ah! Line continuation!

Started by therevills, January 28, 2019, 04:35:06

Previous topic - Next topic

therevills

I wanted to split up a large While condition so I added the line continuation but I messed it up and it took a long time to find and fix!! G'ah!  >:(


While obj.var = 1 Or obj.var = 2 Or obj.var = 3 Or obj.var = 4 ..
         obj.var =5 Or obj.var =6 Or obj.var = 7

superMode = True

Wend


Stop the mistake  :P

Holzchopf

Quote from: therevills on January 28, 2019, 04:35:06Stop the mistake  :P

You're missing an "Or" there.

Also, why not just:
While obj.var > 0 And obj.var < 8
superMode = True

Wend

therevills

Quote from: Holzchopf on January 28, 2019, 06:32:34
You're missing an "Or" there.
Yep! Easy when you can highlight the error :)

Quote
Also, why not just:
While obj.var > 0 And obj.var < 8
superMode = True

Wend


That was just an example to show the error, the proper code is more complex...

I was surprised BMX compiled...

TomToad

Quote from: therevills on January 28, 2019, 08:17:05
I was surprised BMX compiled...
Yeup, blitzmax divides up lines whenever it makes sense (to the compiler) so this:
SuperStrict Local a:Int = 10 Print a
is legal.

In your case, the continuation marks make no difference as the compiler splits at that point anyway without the Or, so you get the While loop only checking if Obj.var = 1, 2, 3, or 4.  If it is either of those values, then the first line of the While loop sets Obj.var to 5. obj.var =5 Or obj.var =6 Or obj.var = 7 is logically divided to obj.var = ((5) Or (obj.var = 6) Or (obj.var = 7)).  The obj.var = 6,7 part will fail and return 0 which is Or'ed with the 5 and then assigned to obj.var.

You can verify all this by executing the example below.
Code (blitzmax) Select
SuperStrict
Type TObj
Field vary:Int
End Type
Local obj:TObj
Local superMode:Int = False
obj.vary = 2
While obj.vary = 1 Or obj.vary = 2 Or obj.vary = 3 Or obj.vary = 4 ..
         obj.vary =5 Or obj.vary =6 Or obj.vary = 7

superMode = True

Wend
Print obj.vary
Print superMode

Just one of the many quirks of BlitzMax.   :D
------------------------------------------------
8 rabbits equals 1 rabbyte.

Henri

Hi Therevills,

this has been the behavior of bmx sense the dawn of time :-)

But I don't see any reason as to why the bcc couldn't catch this continuation error, so you could raise an issue here https://github.com/bmx-ng/bcc/issues

-Henri
- Got 01100011 problems, but the bit ain't 00000001

therevills

Quote from: TomToad on January 28, 2019, 10:58:36
sets Obj.var to 5. obj.var =5 Or obj.var =6 Or obj.var = 7 is logically divided to obj.var = ((5) Or (obj.var = 6) Or (obj.var = 7)).  The obj.var = 6,7 part will fail and return 0 which is Or'ed with the 5 and then assigned to obj.var.

Yep! When I was testing I noticed my variable was set to a strange value and it took a bit of time to work the issue :)