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
This commit is contained in:
Aaron Patterson 2024-01-11 14:50:09 -08:00 коммит произвёл Aaron Patterson
Родитель eb8df2fa7a
Коммит 371256775f
1 изменённых файлов: 12 добавлений и 0 удалений

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

@ -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