April 24, 2019, 11:51:30 PM

Author Topic: G'ah! Line continuation!  (Read 282 times)

Offline therevills

  • Hero Member
  • *****
  • Posts: 520
G'ah! Line continuation!
« on: January 28, 2019, 04:35:06 AM »
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!  >:(

Code: [Select]
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

Offline Holzchopf

  • Full Member
  • ***
  • Posts: 139
Re: G'ah! Line continuation!
« Reply #1 on: January 28, 2019, 06:32:34 AM »
Stop the mistake  :P

You're missing an "Or" there.

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

Wend

Offline therevills

  • Hero Member
  • *****
  • Posts: 520
Re: G'ah! Line continuation!
« Reply #2 on: January 28, 2019, 08:17:05 AM »
You're missing an "Or" there.
Yep! Easy when you can highlight the error :)

Quote
Also, why not just:
Code: [Select]
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...

Offline TomToad

  • Sr. Member
  • ****
  • Posts: 371
Re: G'ah! Line continuation!
« Reply #3 on: January 28, 2019, 10:58:36 AM »
I was surprised BMX compiled...
Yeup, blitzmax divides up lines whenever it makes sense (to the compiler) so this:
Code: [Select]
SuperStrict Local a:Int = 10 Print ais 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
  1. SuperStrict
  2. Type TObj
  3.         Field vary:Int
  4. End Type
  5. Local obj:TObj
  6. Local superMode:Int = False
  7. obj.vary = 2
  8. While obj.vary = 1 Or obj.vary = 2 Or obj.vary = 3 Or obj.vary = 4 ..
  9.          obj.vary =5 Or obj.vary =6 Or obj.vary = 7
  10.  
  11.         superMode = True
  12.  
  13. Wend
  14. Print obj.vary
  15. Print superMode
  16.  
Just one of the many quirks of BlitzMax.   :D
------------------------------------------------
8 rabbits equals 1 rabbyte.

Offline Henri

  • Full Member
  • ***
  • Posts: 187
Re: G'ah! Line continuation!
« Reply #4 on: January 28, 2019, 11:09:34 AM »
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

Offline therevills

  • Hero Member
  • *****
  • Posts: 520
Re: G'ah! Line continuation!
« Reply #5 on: January 28, 2019, 10:22:23 PM »
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 :)