CommandHelper

CommandHelper

46.5k Downloads

Weird array index behaviour

LadyCailinBot opened this issue ยท 3 comments

commented

CMDHELPER-3040 - Reported by Nessiesson

In an attempt to make a workaround for CMDHELPER-3039, I discovered that the following code:
array(string(1)."": 2);
returns the "normal" (i.e. non-associative) array:
{1 2}
Upon further inspection, it seems that the array is of size one and its value is the string: "1 2"

commented

Comment by Pieter12345

Confirmed.
array(string(1):2)[0] returns "Mismatched paranthesis".
array(string(1)."":2)[0] returns "1 2".
array(string(1).'':2)[0] returns "1 2".
array(concat('test',''):'hello')[0] returns "Mismatches paranthesis".
@A = 'test'; array(@A:'hello') returns "test" and "{:hello}". array_keys() returns {} on this array. array_size() returns 1 though.

commented

Comment by PseudoKnight

For anybody wondering, these are all improper uses of array() and breaks its special handling. The bug is that it doesn't give appropriate CH exceptions. As always, if you want to use non literal strings or numbers as indexes, use array_set().

commented

Comment by LadyCailin

I fixed this case, but I also fixed the generic case if you attempt to concat a label, as that should never actually happen. For instance, in this (more plausible) case, where you forgot a comma: array(1: 1 2: 2), previously this would gladly accept the input, and do who knows what. Now, this is a compile error.