зеркало из https://github.com/github/ruby.git
[PRISM] Fixed rest in MultiTargetNodes
This commit is contained in:
Родитель
aaeccc2924
Коммит
5c8e1911ca
|
@ -3711,9 +3711,12 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
|
|||
}
|
||||
case PM_MULTI_TARGET_NODE: {
|
||||
pm_multi_target_node_t *cast = (pm_multi_target_node_t *) node;
|
||||
bool has_rest_expression = (cast->rest &&
|
||||
PM_NODE_TYPE_P(cast->rest, PM_SPLAT_NODE) &&
|
||||
(((pm_splat_node_t *)cast->rest)->expression));
|
||||
|
||||
if (cast->lefts.size) {
|
||||
int flag = (int) (bool) cast->rights.size;
|
||||
int flag = (int) (bool) cast->rights.size || has_rest_expression;
|
||||
ADD_INSN2(ret, &dummy_line_node, expandarray, INT2FIX(cast->lefts.size), INT2FIX(flag));
|
||||
for (size_t index = 0; index < cast->lefts.size; index++) {
|
||||
PM_COMPILE_NOT_POPPED(cast->lefts.nodes[index]);
|
||||
|
@ -3726,6 +3729,11 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
|
|||
PM_COMPILE_NOT_POPPED(cast->rights.nodes[index]);
|
||||
}
|
||||
}
|
||||
|
||||
if (has_rest_expression) {
|
||||
pm_node_t *expression = ((pm_splat_node_t *)cast->rest)->expression;
|
||||
PM_COMPILE_NOT_POPPED(expression);
|
||||
}
|
||||
return;
|
||||
}
|
||||
case PM_MULTI_WRITE_NODE: {
|
||||
|
|
|
@ -502,6 +502,9 @@ module Prism
|
|||
assert_prism_eval("a, (b, c) = [1, 2, 3]; b")
|
||||
assert_prism_eval("a, (b, c) = [1, 2, 3]; c")
|
||||
assert_prism_eval("a, (b, c) = [1, [2, 3]]; c")
|
||||
assert_prism_eval("a, (b, *c) = [1, [2, 3]]; c")
|
||||
assert_prism_eval("a, (b, *c) = 1, [2, 3]; c")
|
||||
assert_prism_eval("a, (b, *) = 1, [2, 3]; b")
|
||||
assert_prism_eval("(a, (b, c, d, e), f, g), h = [1, [2, 3]], 4, 5, [6, 7]; c")
|
||||
end
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче