[PRISM] Small fixes to parameters ordering and methods

This commit is contained in:
Jemma Issroff 2023-11-13 11:32:39 -08:00
Родитель e4dd8f6c9c
Коммит 1acea50100
2 изменённых файлов: 20 добавлений и 5 удалений

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

@ -3656,10 +3656,14 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
for (size_t i = 0; i < keywords_list->size; i++) {
pm_node_t *keyword_parameter_node = keywords_list->nodes[i];
pm_constant_id_t name;
switch PM_NODE_TYPE(keyword_parameter_node) {
case PM_OPTIONAL_KEYWORD_PARAMETER_NODE: {
pm_node_t *value = ((pm_optional_keyword_parameter_node_t *)keyword_parameter_node)->value;
pm_optional_keyword_parameter_node_t *cast = ((pm_optional_keyword_parameter_node_t *)keyword_parameter_node);
pm_node_t *value = cast->value;
name = cast->name;
if (pm_static_literal_p(value)) {
rb_ary_push(default_values, pm_static_literal_value(value, scope_node, parser));
@ -3672,8 +3676,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
break;
}
case PM_REQUIRED_KEYWORD_PARAMETER_NODE: {
pm_required_keyword_parameter_node_t *cast = (pm_required_keyword_parameter_node_t *)keyword_parameter_node;
ids[keyword->required_num] = pm_constant_id_lookup(scope_node, cast->name);
name = ((pm_required_keyword_parameter_node_t *)keyword_parameter_node)->name;
keyword->required_num++;
break;
}
@ -3681,8 +3684,12 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
rb_bug("Unexpected keyword parameter node type");
}
}
ids[i] = pm_constant_id_lookup(scope_node, name);
}
keyword->table = ids;
VALUE *dvs = ALLOC_N(VALUE, RARRAY_LEN(default_values));
for (int i = 0; i < RARRAY_LEN(default_values); i++) {
@ -3695,7 +3702,6 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
}
keyword->default_values = dvs;
keyword->table = ids;
}
if (parameters_node) {
@ -3712,7 +3718,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
if (!body->param.flags.has_kw) {
body->param.keyword = keyword = ZALLOC_N(struct rb_iseq_param_keyword, 1);
}
keyword->rest_start = (int) locals_size;
keyword->rest_start = (int) locals_size - (parameters_node->block ? 2 : 1);
body->param.flags.has_kwrest = true;
}
}

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

@ -787,6 +787,15 @@ module Prism
)
end
def test_method_parameters
assert_prism_eval(<<-CODE)
def self.prism_test_method_parameters(a, b=1, *c, d:, e: 2, **f, &g)
end
method(:prism_test_method_parameters).parameters
CODE
end
def test_LambdaNode
assert_prism_eval("-> { to_s }.call")
end