summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Patterson <tenderlove@ruby-lang.org>2024-01-23 13:33:31 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2024-01-24 12:04:44 -0800
commit8b7e78f156fb566b47ea3ff7701e18486b0e2dac (patch)
tree437578d16598350b602e11bcb6e65b99f5cda5b6
parentbb6af9287b2002c736e1f50a74a57922f61e8a53 (diff)
Fix local table size and index for required post underscore
Co-Authored-By: Matt Valentine-House <matt@eightbitraptor.com>
-rw-r--r--prism_compile.c10
-rw-r--r--test/ruby/test_compile_prism.rb4
2 files changed, 12 insertions, 2 deletions
diff --git a/prism_compile.c b/prism_compile.c
index 163eaf1b09..e15d0627ed 100644
--- a/prism_compile.c
+++ b/prism_compile.c
@@ -6372,7 +6372,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
// additional anonymous local not represented in the locals table
// We want to account for this in our table size
pm_node_t *required = posts_list->nodes[i];
- if (PM_NODE_TYPE_P(required, PM_MULTI_TARGET_NODE)) {
+ if (PM_NODE_TYPE_P(required, PM_MULTI_TARGET_NODE) || PM_NODE_FLAG_P(required, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
table_size++;
}
}
@@ -6541,8 +6541,14 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
// ^
case PM_REQUIRED_PARAMETER_NODE: {
pm_required_parameter_node_t * param = (pm_required_parameter_node_t *)post_node;
+ if (PM_NODE_FLAG_P(param, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
+ ID local = pm_constant_id_lookup(scope_node, param->name);
+ local_table_for_iseq->ids[local_index] = local;
+ }
+ else {
- pm_insert_local_index(param->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
+ pm_insert_local_index(param->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
+ }
break;
}
default: {
diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb
index 7f4cf49bb4..e9bf819ea6 100644
--- a/test/ruby/test_compile_prism.rb
+++ b/test/ruby/test_compile_prism.rb
@@ -1545,6 +1545,10 @@ a
CODE
end
+ def test_repeated_required_post_underscore
+ assert_prism_eval("def self.m(_, _, *_, _); _; end; method(:m).parameters")
+ end
+
def test_repeated_splat_underscore
assert_prism_eval("def self.m(_, _, _ = 1, _ = 2, *_); end; method(:m).parameters")
end