It_took_my_meds
(Hey THIS is FUN)
2006-05-18 01:33 AM
Bug with arrays

Hi All,

I have come across a strange bug with arrays so I am posting it here to bring it to Ruud's attention. The following code shows the problem.

Code:
Break On 

$a = 2,3,4,5,6,7
$b = "a","b","c","d","e","f"
? $a[1] ; 3
? $b[3] ; "d"
; $b[$a[1]] should equal "d"
; KiX evaluates instead of assigning in the next 2 lines
? $b[$a[1]] = "d" ;True
? $b[$a[1]] = "j" ;False
? $b[$a[1]] ;hasn't been changed to "j" it still equals "d"

Get $



Instead of assigning "j" to $b[$a[1]], KiX evaluates whether or not $b[$a[1]] equals "j". I believe this is incorrect behaviour.

Regards,

Richard


ShawnAdministrator
(KiX Supporter)
2006-05-18 02:27 AM
Re: Bug with arrays

I believe you are correct in believing this is incorrect behavior. Good catch btw.

ShawnAdministrator
(KiX Supporter)
2006-05-18 02:54 AM
Re: Bug with arrays

ja, looks like anytime you use an array variable inside array brackets, it falls over ... like this works (assumes func() returns zero say):

$b[func()] = "a"

but this breaks it again (assume func returns the value of its parm):

$b[func($a[0])] = "a"

and trying to fake it out with VAL() or math tricks no work:

$b[val($a[0])] = "a"
$b[0+$a[0]] = "a"


Richard H.Administrator
(KiX Supporter)
2006-05-18 08:57 AM
Re: Bug with arrays

When postings issues please include the version(s) of KiXtart that you've tested on.

It's a nasty little bug though, well done on finding it.

I never did like using "=" for different tasks and deciding intent based on context. The odd thing is that I'm sure I've used this sort of indirect reference in the past.


It_took_my_meds
(Hey THIS is FUN)
2006-05-18 10:32 AM
Re: Bug with arrays

Testing shows that this bug first appeared in version 4.00 and has been present in all versions since then. It wasn't present in version 3.63 and older versions.
Regards,
Richard


It_took_my_meds
(Hey THIS is FUN)
2006-05-19 01:28 AM
Re: Bug with arrays

Interestingly, the bug only works one way.
Code:
$j = $b[$a[1]]

works as expected


Richard H.Administrator
(KiX Supporter)
2006-05-19 10:03 AM
Re: Bug with arrays

The interpreter only needs to consider the LHS of the expression for the context to determine if the "=" is being used for comparison or assignment - the RHS always simplifies to a value so isn't significant.

Howard Bullock
(KiX Supporter)
2006-05-21 05:32 PM
Re: Bug with arrays

To remove the duplicity of the "=" sign, that is evaluation of equality and assignment of a value, should Ruud consider providing different operators for each function in the 5.x timeframe?

Perl uses:

eq, ne for string equality evaluation
== for numeric evaluation

= for assignment of a value to a variable.

I am not advocating that KiX become Perl like. It is just an example of the different functionality.


Richard H.Administrator
(KiX Supporter)
2006-05-22 09:55 AM
Re: Bug with arrays

Would have been great, but Ruud has already used "==" for case sensitive tests.

Howard Bullock
(KiX Supporter)
2006-05-22 02:50 PM
Re: Bug with arrays

I realize that "==" already a place in KiX, I am sure he could rationalize some replacement.

LonkeroAdministrator
(KiX Master Guru)
2006-05-28 02:01 PM
Re: Bug with arrays

I wouldn't go there though.
too huge change, imho.


It_took_my_meds
(Hey THIS is FUN)
2006-06-06 01:16 AM
Re: Bug with arrays

Just a friendly reminder... this bug has not been addressed in 4.52 rc1.

Ruud van Velsen
(Hey THIS is FUN)
2006-06-13 05:59 PM
Re: Bug with arrays

Just to confirm: this is a bug. I will fix this in the final 4.52 build.

Excellent find, thanks!

Ruud