Skip to content

Commit

Permalink
Merge pull request #3306 from tenderlove/numbered-param
Browse files Browse the repository at this point in the history
Same numbered param cannot be used in child blocks
  • Loading branch information
tenderlove authored Dec 12, 2024
2 parents 5f11d52 + d4fc441 commit fbad866
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -16408,14 +16408,15 @@ static pm_node_t *
parse_variable(pm_parser_t *parser) {
pm_constant_id_t name_id = pm_parser_constant_id_token(parser, &parser->previous);
int depth;
bool is_numbered_param = pm_token_is_numbered_parameter(parser->previous.start, parser->previous.end);

if ((depth = pm_parser_local_depth_constant_id(parser, name_id)) != -1) {
if (!is_numbered_param && ((depth = pm_parser_local_depth_constant_id(parser, name_id)) != -1)) {
return (pm_node_t *) pm_local_variable_read_node_create_constant_id(parser, &parser->previous, name_id, (uint32_t) depth, false);
}

pm_scope_t *current_scope = parser->current_scope;
if (!current_scope->closed && !(current_scope->parameters & PM_SCOPE_PARAMETERS_IMPLICIT_DISALLOWED)) {
if (pm_token_is_numbered_parameter(parser->previous.start, parser->previous.end)) {
if (is_numbered_param) {
// When you use a numbered parameter, it implies the existence of
// all of the locals that exist before it. For example, referencing
// _2 means that _1 must exist. Therefore here we loop through all
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-> { _1 + -> { _1 } }
^~ numbered parameter is already used in outer block

0 comments on commit fbad866

Please sign in to comment.