LordGolias/sqf

Priority of + for strings and arrays

Closed this issue · 4 comments

xCtrl ctrlSetText "A" + "B"; // Works (ctrl = "AB")
// [1,22]:error:Binary operator "+" arguments must be [(Number,Number),(String,String),(Array,Array)] 
// (lhs is Nothing, rhs is String)

["X", "Y"] call { // similar but different if vars are "Anything"
    params ["_param1", "_param2"];
    xCtrl ctrlSetText _param1 + _param2; // Works (ctrl = "XY")
};
// [7,30]:error:Binary operator "+" arguments must be [(Number,Number),(String,String),(Array,Array)] 
// (lhs is Nothing, rhs is Anything)

["A"] + ["B"] params ["_x", "_y"];  // Works ([_x, _y] = ["A","B"])
// [12,6]:error:Binary operator "+" arguments must be [(Number,Number),(String,String),(Array,Array)] 
// (lhs is Array, rhs is Boolean)

Well, this was an important one, since it was essentially a problem in getting the right precedences. Fortunately, the solution was only to change == to <=.

Thanks a lot @PabstMirror for the report!

1 and 2 pass, 3rd still shows error

[12,6]:error:Binary operator "+" arguments must be [(Number,Number),(String,String),(Array,Array)] (lhs is Array, rhs is Boolean)

Precedence was incorrectly computed (and we had a wrong test case :/). count[1]+[1] gave no error, when, in fact, + had precedence over binaries. I added a whole bunch of different cases to check that everything works now.

Can you double check and close this issue if you feel it is solved? (not the particular sum of strings or arrays, the whole precedence issue)

Thanks a lot for the patience, @PabstMirror.

Looks like it's working great now, thanks