Fix local table size and variable offset for repeated keywords

Co-Authored-By: Matt Valentine-House <matt@eightbitraptor.com>
This commit is contained in:
Aaron Patterson 2024-01-23 13:41:34 -08:00 коммит произвёл Aaron Patterson
Родитель 8b7e78f156
Коммит 13c76e40d3
2 изменённых файлов: 27 добавлений и 2 удалений

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

@ -6378,6 +6378,15 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
}
}
if (keywords_list && keywords_list->size) {
for (size_t i = 0; i < keywords_list->size; i++) {
pm_node_t *keyword_parameter_node = keywords_list->nodes[i];
if (PM_NODE_FLAG_P(keyword_parameter_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
table_size++;
}
}
}
if (block_param_keyword_rest) {
table_size++;
}
@ -6583,7 +6592,13 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
name = ((pm_required_keyword_parameter_node_t *)keyword_parameter_node)->name;
keyword->required_num++;
ID local = pm_constant_id_lookup(scope_node, name);
pm_insert_local_index(name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
if (PM_NODE_FLAG_P(keyword_parameter_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
local_table_for_iseq->ids[local_index] = local;
}
else {
pm_insert_local_index(name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
}
local_index++;
ids[kw_index++] = local;
}
@ -6613,7 +6628,12 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
}
ID local = pm_constant_id_lookup(scope_node, name);
pm_insert_local_index(name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
if (PM_NODE_FLAG_P(keyword_parameter_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
local_table_for_iseq->ids[local_index] = local;
}
else {
pm_insert_local_index(name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
}
ids[kw_index++] = local;
local_index++;
}

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

@ -1545,6 +1545,11 @@ a
CODE
end
def test_repeated_required_keyword_underscore
assert_prism_eval("def self.m(_, _, *_, _, _:); _; end; method(:m).parameters")
assert_prism_eval("def self.m(_, _, *_, _, _:, _: 2); _; end; method(:m).parameters")
end
def test_repeated_required_post_underscore
assert_prism_eval("def self.m(_, _, *_, _); _; end; method(:m).parameters")
end