GLBasic forum

Main forum => Bug Reports => Topic started by: MrTAToad on 2014-Jun-11

Title: IIF invalid assignment
Post by: MrTAToad on 2014-Jun-11
When using IIF with equality comparison, the variable being compared has it's value changed to that being compares,  For example :

Code (glbasic) Select
LOCAL a%=7
LOCAL b%=0

DEBUG a%+" "+b%+"\n"
b%=IIF(a%=8,1,2)
DEBUG a%+" "+b%+"\n"


In this example, a% gets set to a value of 8 (and b% is set to 1).  a% should be kept at 7, as we're testing for equality and not assigning.

And <> can't be used with this command for some reason.
Title: Re: IIF invalid assignment
Post by: kanonet on 2014-Jun-11
Quote from: MrTAToad on 2014-Jun-11(and b% is set to 1)
This is correct for your example.

But your example gets translated to
Code (glbasic) Select
b=IIF(a=8,1,2); so the GPC fails to translate = to ==. That bug is just an other prove that it was a bad idea to use same operator for assignment and comparison.
Title: Re: IIF invalid assignment
Post by: MrTAToad on 2014-Jun-11
Indeed - the compiler needs to know = should be used for comparison in IIF and not for value assignment.
Title: Re: IIF invalid assignment
Post by: Kitty Hello on 2014-Jun-12
Oopsie Daisys

Gesendet von meinem GT-N7100 mit Tapatalk

Title: Re: IIF invalid assignment
Post by: Kitty Hello on 2014-Jun-25
Fixed it. It was a bug with the equal sign right of an assignment!
Code (glbasic) Select

LOCAL a% = IIF(1=1, 1, 2)
LOCAL b% = RND(3=4)
LOCAL c% = 4=5=6

works now (next update)
Title: Re: IIF invalid assignment
Post by: kanonet on 2014-Aug-11
It is not fixed in 12.243 the logfile is wrong on this.

The code from 1st post still fails, since "b=IIF(a=35,3,4)" translated to "b=IIF(a=35,3,4);" instead of "b=IIF(a==35,3,4);". Therefore "b=IIF(35=a,3,4);" is not even compiling. :giveup:
Title: Re: IIF invalid assignment
Post by: MrTAToad on 2014-Aug-12
Indeed!
Title: Re: IIF invalid assignment
Post by: Kitty Hello on 2014-Aug-20
blimey!
Title: Re: IIF invalid assignment
Post by: matchy on 2014-Aug-20
 :D :D
Title: Re: IIF invalid assignment
Post by: Kitty Hello on 2014-Aug-29
ok, fixed in next update.