|
|
|||||||
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 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 |
||||||||
|
|
|||||||
I believe you are correct in believing this is incorrect behavior. Good catch btw. |
||||||||
|
|
|||||||
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" |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
Interestingly, the bug only works one way. Code: $j = $b[$a[1]] works as expected |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
Would have been great, but Ruud has already used "==" for case sensitive tests. |
||||||||
|
|
|||||||
I realize that "==" already a place in KiX, I am sure he could rationalize some replacement. |
||||||||
|
|
|||||||
I wouldn't go there though. too huge change, imho. |
||||||||
|
|
|||||||
Just a friendly reminder... this bug has not been addressed in 4.52 rc1. |
||||||||
|
|
|||||||
Just to confirm: this is a bug. I will fix this in the final 4.52 build. Excellent find, thanks! Ruud |