dedmen / ArmaScriptCompiler

GNU General Public License v3.0
27 stars 12 forks source link

Params const optimization is not a constant in all cases #14

Closed dedmen closed 3 years ago

dedmen commented 3 years ago
params ["_unit", "_pos", ["_target", objNull], ["_buildings", []]];
_buildings pushBack [1,2,3];

Compiles fine. But after first run, assembly prints this

push ["_unit","_pos",["_target",<NULL-object>],["_buildings",[[1,2,3]]]]
callFunction params;

pushBack modified the reference inside the compiled script. Need to insert + operator call between the const array and params call, if the default values contain an array because otherwise the array will leak into the script.

https://github.com/dedmen/ArmaScriptCompiler/blob/master/src/optimizer/optimizerModuleConstantFold.cpp#L230

dedmen commented 3 years ago

Fixed in https://github.com/dedmen/ArmaScriptCompiler/commit/b2d55a67aeedec2eb896c223a9333fdcb3d0126e