Skip to content

Commit 8c7f4db

Browse files
kddnewtonmatzbot
authored andcommitted
[ruby/prism] Fix modifier rescue pattern matching
[Bug #21713] ruby/prism@02c944c055
1 parent a2db2d4 commit 8c7f4db

6 files changed

Lines changed: 21 additions & 0 deletions

prism/prism.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21740,6 +21740,19 @@ parse_expression(pm_parser_t *parser, pm_binding_power_t binding_power, bool acc
2174021740
return node;
2174121741
}
2174221742
break;
21743+
case PM_RESCUE_MODIFIER_NODE:
21744+
// A rescue modifier whose handler is a one-liner pattern match
21745+
// (=> or in) produces a statement. That means it cannot be
21746+
// extended by operators above the modifier level.
21747+
if (pm_binding_powers[parser->current.type].left > PM_BINDING_POWER_MODIFIER) {
21748+
pm_rescue_modifier_node_t *cast = (pm_rescue_modifier_node_t *) node;
21749+
pm_node_t *rescue_expression = cast->rescue_expression;
21750+
21751+
if (PM_NODE_TYPE_P(rescue_expression, PM_MATCH_REQUIRED_NODE) || PM_NODE_TYPE_P(rescue_expression, PM_MATCH_PREDICATE_NODE)) {
21752+
return node;
21753+
}
21754+
}
21755+
break;
2174321756
default:
2174421757
break;
2174521758
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
'a' rescue 2 in 3.upcase
22
^ unexpected '.', expecting end-of-input
3+
^ unexpected '.', ignoring it
34

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
1 rescue 2 in 3 << 4
22
^~ unexpected <<, expecting end-of-input
3+
^~ unexpected <<, ignoring it
34

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
1 rescue 2 => 3.inspect
22
^ unexpected '.', expecting end-of-input
3+
^ unexpected '.', ignoring it
34

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
1 rescue 2 => 3 ** 4
22
^~ unexpected '**', expecting end-of-input
3+
^~ unexpected '**', ignoring it
34

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
a rescue b => c in d
2+
^~ unexpected 'in', expecting end-of-input
3+
^~ unexpected 'in', ignoring it
4+

0 commit comments

Comments
 (0)