Skip to content

Commit dbcaffa

Browse files
committed
Reject invalid dot as after match predicate and match required
Partially fixes: #3171
1 parent 93c0474 commit dbcaffa

7 files changed

+44
-0
lines changed

src/prism.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21420,6 +21420,32 @@ parse_expression_infix(pm_parser_t *parser, pm_node_t *node, pm_binding_power_t
2142021420
}
2142121421
case PM_TOKEN_AMPERSAND_DOT:
2142221422
case PM_TOKEN_DOT: {
21423+
switch (PM_NODE_TYPE(node)) {
21424+
case PM_RESCUE_MODIFIER_NODE: {
21425+
pm_rescue_modifier_node_t *cast = (pm_rescue_modifier_node_t *) node;
21426+
if (PM_NODE_TYPE_P(cast->rescue_expression, PM_MATCH_PREDICATE_NODE) || PM_NODE_TYPE_P(cast->rescue_expression, PM_MATCH_REQUIRED_NODE)) {
21427+
PM_PARSER_ERR_TOKEN_FORMAT(parser, parser->current, PM_ERR_EXPECT_EOL_AFTER_STATEMENT, pm_token_type_human(parser->current.type));
21428+
}
21429+
break;
21430+
}
21431+
case PM_AND_NODE: {
21432+
pm_and_node_t *cast = (pm_and_node_t *) node;
21433+
if (PM_NODE_TYPE_P(cast->right, PM_MATCH_PREDICATE_NODE) || PM_NODE_TYPE_P(cast->right, PM_MATCH_REQUIRED_NODE)) {
21434+
PM_PARSER_ERR_TOKEN_FORMAT(parser, parser->current, PM_ERR_EXPECT_EOL_AFTER_STATEMENT, pm_token_type_human(parser->current.type));
21435+
}
21436+
break;
21437+
}
21438+
case PM_OR_NODE: {
21439+
pm_or_node_t *cast = (pm_or_node_t *) node;
21440+
if (PM_NODE_TYPE_P(cast->right, PM_MATCH_PREDICATE_NODE) || PM_NODE_TYPE_P(cast->right, PM_MATCH_REQUIRED_NODE)) {
21441+
PM_PARSER_ERR_TOKEN_FORMAT(parser, parser->current, PM_ERR_EXPECT_EOL_AFTER_STATEMENT, pm_token_type_human(parser->current.type));
21442+
}
21443+
break;
21444+
}
21445+
default:
21446+
break;
21447+
}
21448+
2142321449
parser_lex(parser);
2142421450
pm_token_t operator = parser->previous;
2142521451
pm_arguments_t arguments = { 0 };
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1 and 2 in 3.inspect
2+
^ unexpected '.', expecting end-of-input
3+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'a' or 1 in 1.upcase
2+
^ unexpected '.', expecting end-of-input
3+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'a' rescue 2 in 3.upcase
2+
^ unexpected '.', expecting end-of-input
3+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1 and 2 => 3.inspect
2+
^ unexpected '.', expecting end-of-input
3+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1 or 2 => 3.inspect
2+
^ unexpected '.', expecting end-of-input
3+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1 rescue 2 => 3.inspect
2+
^ unexpected '.', expecting end-of-input
3+

0 commit comments

Comments
 (0)