[PRISM] Added tests for ForwardingParameterNode, KeywordRestParameterNode

This commit is contained in:
Jemma Issroff 2023-11-07 19:28:21 -03:00
Родитель 26cff6ae2b
Коммит 70e4ff9feb
2 изменённых файлов: 16 добавлений и 2 удалений

Просмотреть файл

@ -1361,7 +1361,9 @@ pm_setup_args(pm_arguments_node_t *arguments_node, int *flags, struct rb_callinf
*flags |= VM_CALL_KW_SPLAT | VM_CALL_KW_SPLAT_MUT;
ADD_SEND(ret, &dummy_line_node, id_core_hash_merge_kwd, INT2FIX(2));
if (len > 1) {
ADD_SEND(ret, &dummy_line_node, id_core_hash_merge_kwd, INT2FIX(2));
}
if ((i < len - 1) && !PM_NODE_TYPE_P(keyword_arg->elements.nodes[i + 1], cur_type)) {
ADD_INSN1(ret, &dummy_line_node, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
@ -3354,7 +3356,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
body->param.keyword = keyword = ZALLOC_N(struct rb_iseq_param_keyword, 1);
keyword->num = (int) keywords_list->size;
body->param.flags.has_kw = TRUE;
body->param.flags.has_kw = true;
const VALUE default_values = rb_ary_hidden_new(1);
const VALUE complex_mark = rb_str_tmp_new(0);
@ -3397,6 +3399,10 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
body->param.flags.accepts_no_kwarg = true;
}
else {
if (!body->param.flags.has_kw) {
body->param.keyword = keyword = ZALLOC_N(struct rb_iseq_param_keyword, 1);
}
keyword->rest_start = (int) locals_size;
body->param.flags.has_kwrest = true;
}
}

Просмотреть файл

@ -900,6 +900,14 @@ module Prism
assert_prism_eval("[1].map { |a; b| b = 2; a + b}")
end
def test_FowardingParameterNode
assert_prism_eval("def prism_test_forwarding_parameter_node(...); end")
end
def test_KeywordRestParameterNode
assert_prism_eval("def prism_test_keyword_rest_parameter_node(a, **b); end")
end
def test_NoKeywordsParameterNode
assert_prism_eval("def prism_test_no_keywords(**nil); end")
assert_prism_eval("def prism_test_no_keywords(a, b = 2, **nil); end")