mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
fix masgn nosplat array rhs bug
The rest lhs variable has to be an empty array if rhs is an array with less elements than pre + post lhs variables. The codegen generated OP_ARRAY with an invalid length (such as 127 for *a, b = []) because rn was negative.
This commit is contained in:
+7
-1
@@ -1615,8 +1615,14 @@ codegen(codegen_scope *s, node *tree, int val)
|
||||
}
|
||||
}
|
||||
if (t->car) { /* rest (len - pre - post) */
|
||||
int rn = len - post - n;
|
||||
int rn;
|
||||
|
||||
if (len < post + n) {
|
||||
rn = 0;
|
||||
}
|
||||
else {
|
||||
rn = len - post - n;
|
||||
}
|
||||
genop(s, MKOP_ABC(OP_ARRAY, cursp(), rhs+n, rn));
|
||||
gen_assignment(s, t->car, cursp(), NOVAL);
|
||||
n += rn;
|
||||
|
||||
Reference in New Issue
Block a user