23
Feb

Cute little Array bug

var a:Array = ["bla"];
a[ uint.MAX_VALUE ] = "bla2";
trace( a.length ); // 0
a.push(1, 2, 3);
trace( a.length ); // 0
trace( a[0] ); // 3
trace( a[ uint.MAX_VALUE ] ); // "bla2"

at wonderfl

don’t ask me how I found it

Tags: ,

  • http://www.wonderwhy-er.com wonderwhy-er

    Lol, I wonder what causes such behavior.

  • James

    I believe this is not a bug, by forcing type cast like int(1) or String(“1″) to the value before push should work exactly. There was once I force the value as String so that it would give a valid type.

    It would be better to use Vector

  • Ben

    Ok, I think that if you try and push more items than the array can cope with then it fails.

    The array can accept uint.MAX_VALUE values but setting
    a[uint.MAX_VALUE] means that the lenght should be (uint.MAX_VALUE+1) which is not possible.

    • http://va.lent.in Valentin

      I know and this is somehow logical, but look at push() behavior.

      • http://www.wonderwhy-er.com wonderwhy-er

        Yeah, very hard to find logic behind 4 and 6 lines behavior.

  • http://www.daylyn.net daylyn

    I wonder what causes such behavior~~