diff options
| author | eileencodes <eileencodes@gmail.com> | 2024-10-01 14:50:45 -0400 |
|---|---|---|
| committer | Kevin Newton <kddnewton@gmail.com> | 2024-12-16 10:51:22 -0500 |
| commit | a21237571e57e1c6992d41424300996303859b3e (patch) | |
| tree | cf3ce94973de1e79fbed590858a3c43eecb58f0f | |
| parent | 8eaa976cbe20ef81a3dd17097337394bf798d7f0 (diff) | |
[ruby/prism] Fix 3112 - disallow commas after block arg
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 ruby/prism#3112.
Fixes: ruby/prism#3112
https://github.com/ruby/prism/commit/754cf8eddc
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/12358
| -rw-r--r-- | prism/prism.c | 7 | ||||
| -rw-r--r-- | test/prism/errors/arguments_after_block.txt | 16 |
2 files changed, 19 insertions, 4 deletions
diff --git a/prism/prism.c b/prism/prism.c index bdcaabf20b..a15529b227 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -14167,9 +14167,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); } @@ -14218,6 +14215,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; } diff --git a/test/prism/errors/arguments_after_block.txt b/test/prism/errors/arguments_after_block.txt index 2d5e06ff77..c33039146f 100644 --- a/test/prism/errors/arguments_after_block.txt +++ b/test/prism/errors/arguments_after_block.txt @@ -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 |
