Local variable assignment to adjacent local variables in comma separated declarations ignore the first variable's assignment and cause it to have no value.
// a = null
// b = 1
local a = 1, b = a;
-----LOCALS
[2] b 1 0
[1] a 1 0
[0] this 0 1
-----dump
[000] _OP_LOADINT 2 1 0 0
Local variable assignment to adjacent local variables in comma separated declarations ignore the first variable's assignment and cause it to have no value.
The source of this issue is at
SQFuncState::AddInstruction()
https://github.com/albertodemichelis/squirrel/blob/7da4a6f196cc4e45f753a46cf0b0a9c125df34e2/squirrel/sqfuncstate.cpp#L519-L530reached from
SQCompiler::LocalDeclStatement()
https://github.com/albertodemichelis/squirrel/blob/7da4a6f196cc4e45f753a46cf0b0a9c125df34e2/squirrel/sqcompiler.cpp#L1067Removing
if(pi._arg0 == i._arg1)
block compiles it identical tolocal a = 1; local b = a;
with optimisations.This can be observed with
_OP_GET
and other instructions listed there._OP_GET
actually assigns the GET-index to the variable.With more variables
Two move instructions in a row are compiled into
_OP_DMOVE
, which works fine. Note howc
is assigned toa
, as assigning it tob
causes the issue.