зеркало из https://github.com/github/ruby.git
Fix local table size / index for repeated kwrest
Co-Authored-By: Matt Valentine-House <matt@eightbitraptor.com>
This commit is contained in:
Родитель
13c76e40d3
Коммит
1817af5074
|
@ -6358,12 +6358,20 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
|
|||
// table size to take it in to account.
|
||||
// def m(foo, *, bar)
|
||||
// ^
|
||||
if (parameters_node && parameters_node->rest) {
|
||||
if (!(PM_NODE_TYPE_P(parameters_node->rest, PM_IMPLICIT_REST_NODE))) {
|
||||
if (!((pm_rest_parameter_node_t *)parameters_node->rest)->name || PM_NODE_FLAG_P(parameters_node->rest, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
|
||||
table_size++;
|
||||
if (parameters_node) {
|
||||
if (parameters_node->rest) {
|
||||
if (!(PM_NODE_TYPE_P(parameters_node->rest, PM_IMPLICIT_REST_NODE))) {
|
||||
if (!((pm_rest_parameter_node_t *)parameters_node->rest)->name || PM_NODE_FLAG_P(parameters_node->rest, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
|
||||
table_size++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// def underscore_parameters(_, **_); _; end
|
||||
// ^^^
|
||||
if (parameters_node->keyword_rest && PM_NODE_FLAG_P(parameters_node->keyword_rest, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
|
||||
table_size++;
|
||||
}
|
||||
}
|
||||
|
||||
if (posts_list) {
|
||||
|
@ -6691,7 +6699,13 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
|
|||
|
||||
pm_constant_id_t constant_id = kw_rest_node->name;
|
||||
if (constant_id) {
|
||||
pm_insert_local_index(constant_id, local_index, index_lookup_table, local_table_for_iseq, scope_node);
|
||||
if (PM_NODE_FLAG_P(kw_rest_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
|
||||
ID local = pm_constant_id_lookup(scope_node, constant_id);
|
||||
local_table_for_iseq->ids[local_index] = local;
|
||||
}
|
||||
else {
|
||||
pm_insert_local_index(constant_id, local_index, index_lookup_table, local_table_for_iseq, scope_node);
|
||||
}
|
||||
}
|
||||
else {
|
||||
local_table_for_iseq->ids[local_index] = PM_CONSTANT_POW;
|
||||
|
|
|
@ -1545,6 +1545,10 @@ a
|
|||
CODE
|
||||
end
|
||||
|
||||
def test_repeated_kw_rest_underscore
|
||||
assert_prism_eval("def self.m(_, **_); _; end; method(:m).parameters")
|
||||
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")
|
||||
|
|
Загрузка…
Ссылка в новой задаче