diff options
author | Alan Wu <XrXr@users.noreply.github.com> | 2024-02-01 18:31:42 -0500 |
---|---|---|
committer | Kevin Newton <kddnewton@gmail.com> | 2024-02-02 18:50:41 -0500 |
commit | 90ae8eaecae00eabd2d7dc8ec7ee1afc53a6bd9d (patch) | |
tree | 8f4f89624ae3d966c4305322f166501d74171ca5 /prism_compile.c | |
parent | 5d646fa136131c18a7a432486c65438abe9790e2 (diff) |
[PRISM] Fix numbered parameters stealing local names
Previously, the local index of numbered parameters were assigned to
names of regular locals, making it hard to read both of them. Use proper
`_[1-9]` numbered parameters. This fixes `test_shapes.rb`.
Also, properly mark the iseq as having lead parameters.
Diffstat (limited to 'prism_compile.c')
-rw-r--r-- | prism_compile.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/prism_compile.c b/prism_compile.c index 79b4caca9d..921d5a5309 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -7039,10 +7039,15 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret, // Fill in any NumberedParameters, if they exist if (scope_node->parameters && PM_NODE_TYPE_P(scope_node->parameters, PM_NUMBERED_PARAMETERS_NODE)) { int maximum = ((pm_numbered_parameters_node_t *)scope_node->parameters)->maximum; + RUBY_ASSERT(0 < maximum && maximum <= 9); for (int i = 0; i < maximum; i++, local_index++) { - pm_constant_id_t constant_id = locals->ids[i]; + const uint8_t param_name[] = { '_', '1' + i }; + pm_constant_id_t constant_id = pm_constant_pool_find(&parser->constant_pool, param_name, 2); + RUBY_ASSERT(constant_id && "parser should fill in any gaps in numbered parameters"); pm_insert_local_index(constant_id, local_index, index_lookup_table, local_table_for_iseq, scope_node); } + body->param.lead_num = maximum; + body->param.flags.has_lead = true; } //********END OF STEP 3********** |