Page 1 of 1 1
Topic Options
#162010 - 2006-05-18 01:33 AM Bug with arrays
It_took_my_meds Offline
Hey THIS is FUN
*****

Registered: 2003-05-07
Posts: 273
Loc: Sydney, Australia
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


Edited by It_took_my_meds (2006-05-18 02:49 AM)

Top
#162011 - 2006-05-18 02:27 AM Re: Bug with arrays
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
I believe you are correct in believing this is incorrect behavior. Good catch btw.
Top
#162012 - 2006-05-18 02:54 AM Re: Bug with arrays
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
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"

Top
#162013 - 2006-05-18 08:57 AM Re: Bug with arrays
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
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.

Top
#162014 - 2006-05-18 10:32 AM Re: Bug with arrays
It_took_my_meds Offline
Hey THIS is FUN
*****

Registered: 2003-05-07
Posts: 273
Loc: Sydney, Australia
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


Edited by It_took_my_meds (2006-05-18 10:35 AM)

Top
#162015 - 2006-05-19 01:28 AM Re: Bug with arrays
It_took_my_meds Offline
Hey THIS is FUN
*****

Registered: 2003-05-07
Posts: 273
Loc: Sydney, Australia
Interestingly, the bug only works one way.
Code:
$j = $b[$a[1]]

works as expected

Top
#162016 - 2006-05-19 10:03 AM Re: Bug with arrays
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
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.
Top
#162017 - 2006-05-21 05:32 PM Re: Bug with arrays
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#162018 - 2006-05-22 09:55 AM Re: Bug with arrays
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Would have been great, but Ruud has already used "==" for case sensitive tests.
Top
#162019 - 2006-05-22 02:50 PM Re: Bug with arrays
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I realize that "==" already a place in KiX, I am sure he could rationalize some replacement.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#162020 - 2006-05-28 02:01 PM Re: Bug with arrays
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I wouldn't go there though.
too huge change, imho.
_________________________
!

download KiXnet

Top
#162021 - 2006-06-06 01:16 AM Re: Bug with arrays
It_took_my_meds Offline
Hey THIS is FUN
*****

Registered: 2003-05-07
Posts: 273
Loc: Sydney, Australia
Just a friendly reminder... this bug has not been addressed in 4.52 rc1.
Top
#162022 - 2006-06-13 05:59 PM Re: Bug with arrays
Ruud van Velsen Moderator Offline
Developer
*****

Registered: 1999-05-06
Posts: 391
Loc: Amsterdam, The Netherlands
Just to confirm: this is a bug. I will fix this in the final 4.52 build.

Excellent find, thanks!

Ruud

Top
Page 1 of 1 1


Moderator:  ShaneEP, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 466 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.064 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.