Skip to content

Commit

Permalink
Fix 3112 - disallow commas after block arg
Browse files Browse the repository at this point in the history
Prism was already disallowing arguments after block args, but in
parse.y, any comma after a block arg is a syntax error. This moves the
error handling into `PM_TOKEN_UAMPERSAND` where we can check if the
current type is `PM_TOKEN_COMMA`then raise an error. I've also updated
the tests to include the examplesfrom #3112.

Fixes: #3112
  • Loading branch information
eileencodes committed Oct 1, 2024
1 parent fb25917 commit 754cf8e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -14127,9 +14127,6 @@ parse_arguments(pm_parser_t *parser, pm_arguments_t *arguments, bool accepts_for
bool parsed_forwarding_arguments = false;

while (!match1(parser, PM_TOKEN_EOF)) {
if (parsed_block_argument) {
pm_parser_err_current(parser, PM_ERR_ARGUMENT_AFTER_BLOCK);
}
if (parsed_forwarding_arguments) {
pm_parser_err_current(parser, PM_ERR_ARGUMENT_AFTER_FORWARDING_ELLIPSES);
}
Expand Down Expand Up @@ -14178,6 +14175,10 @@ parse_arguments(pm_parser_t *parser, pm_arguments_t *arguments, bool accepts_for
arguments->block = argument;
}

if (parser->current.type == PM_TOKEN_COMMA) {
pm_parser_err_current(parser, PM_ERR_ARGUMENT_AFTER_BLOCK);
}

parsed_block_argument = true;
break;
}
Expand Down
16 changes: 15 additions & 1 deletion test/prism/errors/arguments_after_block.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
a(&block, foo)
^~~ unexpected argument after a block argument
^ unexpected argument after a block argument
a(&block,)
^ unexpected argument after a block argument
a.(&block,)
^ unexpected argument after a block argument
a[&block,]
^ unexpected argument after a block argument
def a(&block)
p(&block,)
^ unexpected argument after a block argument
a.(&block,)
^ unexpected argument after a block argument
a[&block,]
^ unexpected argument after a block argument
end

0 comments on commit 754cf8e

Please sign in to comment.