Skip to content

Commit 587867d

Browse files
committed
[Bug #21345] Fix accepting multiple rest patterns with leading match
Related: * https://bugs.ruby-lang.org/issues/20765 * ruby#2915
1 parent 5202e5f commit 587867d

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

src/prism.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13123,14 +13123,6 @@ match8(const pm_parser_t *parser, pm_token_type_t type1, pm_token_type_t type2,
1312313123
return match1(parser, type1) || match1(parser, type2) || match1(parser, type3) || match1(parser, type4) || match1(parser, type5) || match1(parser, type6) || match1(parser, type7) || match1(parser, type8);
1312413124
}
1312513125

13126-
/**
13127-
* Returns true if the current token is any of the nine given types.
13128-
*/
13129-
static inline bool
13130-
match9(const pm_parser_t *parser, pm_token_type_t type1, pm_token_type_t type2, pm_token_type_t type3, pm_token_type_t type4, pm_token_type_t type5, pm_token_type_t type6, pm_token_type_t type7, pm_token_type_t type8, pm_token_type_t type9) {
13131-
return match1(parser, type1) || match1(parser, type2) || match1(parser, type3) || match1(parser, type4) || match1(parser, type5) || match1(parser, type6) || match1(parser, type7) || match1(parser, type8) || match1(parser, type9);
13132-
}
13133-
1313413126
/**
1313513127
* If the current token is of the specified type, lex forward by one token and
1313613128
* return true. Otherwise, return false. For example:
@@ -17675,7 +17667,7 @@ parse_pattern(pm_parser_t *parser, pm_constant_id_list_t *captures, uint8_t flag
1767517667
// Gather up all of the patterns into the list.
1767617668
while (accept1(parser, PM_TOKEN_COMMA)) {
1767717669
// Break early here in case we have a trailing comma.
17678-
if (match9(parser, PM_TOKEN_KEYWORD_THEN, PM_TOKEN_BRACE_RIGHT, PM_TOKEN_BRACKET_RIGHT, PM_TOKEN_PARENTHESIS_RIGHT, PM_TOKEN_SEMICOLON, PM_TOKEN_NEWLINE, PM_TOKEN_EOF,PM_TOKEN_KEYWORD_AND, PM_TOKEN_KEYWORD_OR)) {
17670+
if (match7(parser, PM_TOKEN_KEYWORD_THEN, PM_TOKEN_BRACE_RIGHT, PM_TOKEN_BRACKET_RIGHT, PM_TOKEN_PARENTHESIS_RIGHT, PM_TOKEN_SEMICOLON, PM_TOKEN_KEYWORD_AND, PM_TOKEN_KEYWORD_OR)) {
1767917671
node = (pm_node_t *) pm_implicit_rest_node_create(parser, &parser->previous);
1768017672
pm_node_list_append(&nodes, node);
1768117673
trailing_rest = true;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
a=>b, *,
2+
^ expected a pattern expression after `,`
3+

0 commit comments

Comments
 (0)