Skip to content

Commit b76504b

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

7 files changed

+44
-0
lines changed

src/prism.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21430,6 +21430,32 @@ parse_expression_infix(pm_parser_t *parser, pm_node_t *node, pm_binding_power_t
2143021430
return (pm_node_t *) pm_call_node_shorthand_create(parser, node, &operator, &arguments);
2143121431
}
2143221432

21433+
switch (PM_NODE_TYPE(node)) {
21434+
case PM_RESCUE_MODIFIER_NODE: {
21435+
pm_rescue_modifier_node_t *cast = (pm_rescue_modifier_node_t *) node;
21436+
if (PM_NODE_TYPE_P(cast->rescue_expression, PM_MATCH_PREDICATE_NODE) || PM_NODE_TYPE_P(cast->rescue_expression, PM_MATCH_REQUIRED_NODE)) {
21437+
PM_PARSER_ERR_TOKEN_FORMAT(parser, operator, PM_ERR_EXPECT_EOL_AFTER_STATEMENT, pm_token_type_human(operator.type));
21438+
}
21439+
break;
21440+
}
21441+
case PM_AND_NODE: {
21442+
pm_and_node_t *cast = (pm_and_node_t *) node;
21443+
if (PM_NODE_TYPE_P(cast->right, PM_MATCH_PREDICATE_NODE) || PM_NODE_TYPE_P(cast->right, PM_MATCH_REQUIRED_NODE)) {
21444+
PM_PARSER_ERR_TOKEN_FORMAT(parser, operator, PM_ERR_EXPECT_EOL_AFTER_STATEMENT, pm_token_type_human(operator.type));
21445+
}
21446+
break;
21447+
}
21448+
case PM_OR_NODE: {
21449+
pm_or_node_t *cast = (pm_or_node_t *) node;
21450+
if (PM_NODE_TYPE_P(cast->right, PM_MATCH_PREDICATE_NODE) || PM_NODE_TYPE_P(cast->right, PM_MATCH_REQUIRED_NODE)) {
21451+
PM_PARSER_ERR_TOKEN_FORMAT(parser, operator, PM_ERR_EXPECT_EOL_AFTER_STATEMENT, pm_token_type_human(operator.type));
21452+
}
21453+
break;
21454+
}
21455+
default:
21456+
break;
21457+
}
21458+
2143321459
pm_token_t message;
2143421460

2143521461
switch (parser->current.type) {
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)