Skip to content

Commit 9ccb069

Browse files
authored
Merge pull request #3242 from ydah/reject-invalid-dot-method-call
Reject invalid dot method call after match predicate or after match required
2 parents 4a14093 + 5c33fa5 commit 9ccb069

7 files changed

+44
-0
lines changed

src/prism.c

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

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

2143921465
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)