diff options
| author | Jemma Issroff <jemmaissroff@gmail.com> | 2023-11-07 19:28:21 -0300 |
|---|---|---|
| committer | Jemma Issroff <jemmaissroff@gmail.com> | 2023-11-08 18:15:47 -0300 |
| commit | 70e4ff9feb9e5f7254f9dbe955dedbf56e73c8d5 (patch) | |
| tree | fa814b521ffcb0af8028b031e4392b1ecc2547fb | |
| parent | 26cff6ae2b7fe2259f942d1cf411c5af891b1de9 (diff) | |
[PRISM] Added tests for ForwardingParameterNode, KeywordRestParameterNode
| -rw-r--r-- | prism_compile.c | 10 | ||||
| -rw-r--r-- | test/ruby/test_compile_prism.rb | 8 |
2 files changed, 16 insertions, 2 deletions
diff --git a/prism_compile.c b/prism_compile.c index ba02517532..7bbc521a9d 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -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; } } diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb index e94b256119..2661bd5bea 100644 --- a/test/ruby/test_compile_prism.rb +++ b/test/ruby/test_compile_prism.rb @@ -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") |
