From 371256775f56881fc6a4d41d47afa63e00199c0d Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 11 Jan 2024 14:50:09 -0800 Subject: [PATCH] Anonymous rest nodes should increase the local table size When we calculate the local table size, we need to account for anonymous "rest" parameters. Since they don't have a name, they won't be in the "locals" table that Prism provides, but we need to reserve room for them anyway. Fixes: https://github.com/ruby/prism/issues/2154 --- prism_compile.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/prism_compile.c b/prism_compile.c index cbae85b9f4..7bba3be0a1 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -5606,6 +5606,18 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret, } } + // If we have an anonymous "rest" node, we'll need to increase the local + // 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) { + table_size++; + } + } + } + if (posts_list) { for (size_t i = 0; i < posts_list->size; i++) { // For each MultiTargetNode, we're going to have one