Skip to content

Commit 2ba5987

Browse files
ydahmatzbot
authored andcommitted
[ruby/prism] Reject invalid dot method call after match predicate or after match required
Partially fixes: ruby/prism#3171 ruby/prism@5c33fa5a1a
1 parent aa77bfd commit 2ba5987

7 files changed

+44
-0
lines changed

prism/prism.c

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

21446+
switch (PM_NODE_TYPE(node)) {
21447+
case PM_RESCUE_MODIFIER_NODE: {
21448+
pm_rescue_modifier_node_t *cast = (pm_rescue_modifier_node_t *) node;
21449+
if (PM_NODE_TYPE_P(cast->rescue_expression, PM_MATCH_PREDICATE_NODE) || PM_NODE_TYPE_P(cast->rescue_expression, PM_MATCH_REQUIRED_NODE)) {
21450+
PM_PARSER_ERR_TOKEN_FORMAT(parser, operator, PM_ERR_EXPECT_EOL_AFTER_STATEMENT, pm_token_type_human(operator.type));
21451+
}
21452+
break;
21453+
}
21454+
case PM_AND_NODE: {
21455+
pm_and_node_t *cast = (pm_and_node_t *) node;
21456+
if (PM_NODE_TYPE_P(cast->right, PM_MATCH_PREDICATE_NODE) || PM_NODE_TYPE_P(cast->right, PM_MATCH_REQUIRED_NODE)) {
21457+
PM_PARSER_ERR_TOKEN_FORMAT(parser, operator, PM_ERR_EXPECT_EOL_AFTER_STATEMENT, pm_token_type_human(operator.type));
21458+
}
21459+
break;
21460+
}
21461+
case PM_OR_NODE: {
21462+
pm_or_node_t *cast = (pm_or_node_t *) node;
21463+
if (PM_NODE_TYPE_P(cast->right, PM_MATCH_PREDICATE_NODE) || PM_NODE_TYPE_P(cast->right, PM_MATCH_REQUIRED_NODE)) {
21464+
PM_PARSER_ERR_TOKEN_FORMAT(parser, operator, PM_ERR_EXPECT_EOL_AFTER_STATEMENT, pm_token_type_human(operator.type));
21465+
}
21466+
break;
21467+
}
21468+
default:
21469+
break;
21470+
}
21471+
2144621472
pm_token_t message;
2144721473

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