Skip to content

Commit c290861

Browse files
kddnewtonmatzbot
authored andcommitted
[ruby/prism] Fix rescue modifier precedence
Fixes [Bug #21048] ruby/prism@07202005cb
1 parent 241ada7 commit c290861

File tree

3 files changed

+241
-4
lines changed

3 files changed

+241
-4
lines changed

prism/prism.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12974,7 +12974,7 @@ typedef struct {
1297412974

1297512975
pm_binding_powers_t pm_binding_powers[PM_TOKEN_MAXIMUM] = {
1297612976
// rescue
12977-
[PM_TOKEN_KEYWORD_RESCUE_MODIFIER] = LEFT_ASSOCIATIVE(PM_BINDING_POWER_MODIFIER_RESCUE),
12977+
[PM_TOKEN_KEYWORD_RESCUE_MODIFIER] = { PM_BINDING_POWER_MODIFIER_RESCUE, PM_BINDING_POWER_COMPOSITION, true, false },
1297812978

1297912979
// if unless until while
1298012980
[PM_TOKEN_KEYWORD_IF_MODIFIER] = LEFT_ASSOCIATIVE(PM_BINDING_POWER_MODIFIER),
@@ -19476,7 +19476,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
1947619476
context_push(parser, PM_CONTEXT_RESCUE_MODIFIER);
1947719477

1947819478
pm_token_t rescue_keyword = parser->previous;
19479-
pm_node_t *value = parse_expression(parser, binding_power, false, false, PM_ERR_RESCUE_MODIFIER_VALUE, (uint16_t) (depth + 1));
19479+
pm_node_t *value = parse_expression(parser, pm_binding_powers[PM_TOKEN_KEYWORD_RESCUE_MODIFIER].right, false, false, PM_ERR_RESCUE_MODIFIER_VALUE, (uint16_t) (depth + 1));
1948019480
context_pop(parser);
1948119481

1948219482
statement = (pm_node_t *) pm_rescue_modifier_node_create(parser, statement, &rescue_keyword, value);
@@ -20697,7 +20697,7 @@ parse_assignment_value(pm_parser_t *parser, pm_binding_power_t previous_binding_
2069720697
pm_token_t rescue = parser->current;
2069820698
parser_lex(parser);
2069920699

20700-
pm_node_t *right = parse_expression(parser, binding_power, false, false, PM_ERR_RESCUE_MODIFIER_VALUE, (uint16_t) (depth + 1));
20700+
pm_node_t *right = parse_expression(parser, pm_binding_powers[PM_TOKEN_KEYWORD_RESCUE_MODIFIER].right, false, false, PM_ERR_RESCUE_MODIFIER_VALUE, (uint16_t) (depth + 1));
2070120701
context_pop(parser);
2070220702

2070320703
return (pm_node_t *) pm_rescue_modifier_node_create(parser, value, &rescue, right);
@@ -20803,7 +20803,7 @@ parse_assignment_values(pm_parser_t *parser, pm_binding_power_t previous_binding
2080320803
}
2080420804
}
2080520805

20806-
pm_node_t *right = parse_expression(parser, binding_power, accepts_command_call_inner, false, PM_ERR_RESCUE_MODIFIER_VALUE, (uint16_t) (depth + 1));
20806+
pm_node_t *right = parse_expression(parser, pm_binding_powers[PM_TOKEN_KEYWORD_RESCUE_MODIFIER].right, accepts_command_call_inner, false, PM_ERR_RESCUE_MODIFIER_VALUE, (uint16_t) (depth + 1));
2080720807
context_pop(parser);
2080820808

2080920809
return (pm_node_t *) pm_rescue_modifier_node_create(parser, value, &rescue, right);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
a rescue b if c
2+
3+
a = b rescue c if d
4+
5+
a, = b rescue c if d
6+
7+
def a = b rescue c if d
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
@ ProgramNode (location: (1,0)-(7,23))
2+
├── flags: ∅
3+
├── locals: [:a]
4+
└── statements:
5+
@ StatementsNode (location: (1,0)-(7,23))
6+
├── flags: ∅
7+
└── body: (length: 4)
8+
├── @ IfNode (location: (1,0)-(1,15))
9+
│ ├── flags: newline
10+
│ ├── if_keyword_loc: (1,11)-(1,13) = "if"
11+
│ ├── predicate:
12+
│ │ @ CallNode (location: (1,14)-(1,15))
13+
│ │ ├── flags: variable_call, ignore_visibility
14+
│ │ ├── receiver: ∅
15+
│ │ ├── call_operator_loc: ∅
16+
│ │ ├── name: :c
17+
│ │ ├── message_loc: (1,14)-(1,15) = "c"
18+
│ │ ├── opening_loc: ∅
19+
│ │ ├── arguments: ∅
20+
│ │ ├── closing_loc: ∅
21+
│ │ └── block: ∅
22+
│ ├── then_keyword_loc: ∅
23+
│ ├── statements:
24+
│ │ @ StatementsNode (location: (1,0)-(1,10))
25+
│ │ ├── flags: ∅
26+
│ │ └── body: (length: 1)
27+
│ │ └── @ RescueModifierNode (location: (1,0)-(1,10))
28+
│ │ ├── flags: newline
29+
│ │ ├── expression:
30+
│ │ │ @ CallNode (location: (1,0)-(1,1))
31+
│ │ │ ├── flags: variable_call, ignore_visibility
32+
│ │ │ ├── receiver: ∅
33+
│ │ │ ├── call_operator_loc: ∅
34+
│ │ │ ├── name: :a
35+
│ │ │ ├── message_loc: (1,0)-(1,1) = "a"
36+
│ │ │ ├── opening_loc: ∅
37+
│ │ │ ├── arguments: ∅
38+
│ │ │ ├── closing_loc: ∅
39+
│ │ │ └── block: ∅
40+
│ │ ├── keyword_loc: (1,2)-(1,8) = "rescue"
41+
│ │ └── rescue_expression:
42+
│ │ @ CallNode (location: (1,9)-(1,10))
43+
│ │ ├── flags: variable_call, ignore_visibility
44+
│ │ ├── receiver: ∅
45+
│ │ ├── call_operator_loc: ∅
46+
│ │ ├── name: :b
47+
│ │ ├── message_loc: (1,9)-(1,10) = "b"
48+
│ │ ├── opening_loc: ∅
49+
│ │ ├── arguments: ∅
50+
│ │ ├── closing_loc: ∅
51+
│ │ └── block: ∅
52+
│ ├── subsequent: ∅
53+
│ └── end_keyword_loc: ∅
54+
├── @ IfNode (location: (3,0)-(3,19))
55+
│ ├── flags: newline
56+
│ ├── if_keyword_loc: (3,15)-(3,17) = "if"
57+
│ ├── predicate:
58+
│ │ @ CallNode (location: (3,18)-(3,19))
59+
│ │ ├── flags: variable_call, ignore_visibility
60+
│ │ ├── receiver: ∅
61+
│ │ ├── call_operator_loc: ∅
62+
│ │ ├── name: :d
63+
│ │ ├── message_loc: (3,18)-(3,19) = "d"
64+
│ │ ├── opening_loc: ∅
65+
│ │ ├── arguments: ∅
66+
│ │ ├── closing_loc: ∅
67+
│ │ └── block: ∅
68+
│ ├── then_keyword_loc: ∅
69+
│ ├── statements:
70+
│ │ @ StatementsNode (location: (3,0)-(3,14))
71+
│ │ ├── flags: ∅
72+
│ │ └── body: (length: 1)
73+
│ │ └── @ LocalVariableWriteNode (location: (3,0)-(3,14))
74+
│ │ ├── flags: newline
75+
│ │ ├── name: :a
76+
│ │ ├── depth: 0
77+
│ │ ├── name_loc: (3,0)-(3,1) = "a"
78+
│ │ ├── value:
79+
│ │ │ @ RescueModifierNode (location: (3,4)-(3,14))
80+
│ │ │ ├── flags: ∅
81+
│ │ │ ├── expression:
82+
│ │ │ │ @ CallNode (location: (3,4)-(3,5))
83+
│ │ │ │ ├── flags: variable_call, ignore_visibility
84+
│ │ │ │ ├── receiver: ∅
85+
│ │ │ │ ├── call_operator_loc: ∅
86+
│ │ │ │ ├── name: :b
87+
│ │ │ │ ├── message_loc: (3,4)-(3,5) = "b"
88+
│ │ │ │ ├── opening_loc: ∅
89+
│ │ │ │ ├── arguments: ∅
90+
│ │ │ │ ├── closing_loc: ∅
91+
│ │ │ │ └── block: ∅
92+
│ │ │ ├── keyword_loc: (3,6)-(3,12) = "rescue"
93+
│ │ │ └── rescue_expression:
94+
│ │ │ @ CallNode (location: (3,13)-(3,14))
95+
│ │ │ ├── flags: variable_call, ignore_visibility
96+
│ │ │ ├── receiver: ∅
97+
│ │ │ ├── call_operator_loc: ∅
98+
│ │ │ ├── name: :c
99+
│ │ │ ├── message_loc: (3,13)-(3,14) = "c"
100+
│ │ │ ├── opening_loc: ∅
101+
│ │ │ ├── arguments: ∅
102+
│ │ │ ├── closing_loc: ∅
103+
│ │ │ └── block: ∅
104+
│ │ └── operator_loc: (3,2)-(3,3) = "="
105+
│ ├── subsequent: ∅
106+
│ └── end_keyword_loc: ∅
107+
├── @ IfNode (location: (5,0)-(5,20))
108+
│ ├── flags: newline
109+
│ ├── if_keyword_loc: (5,16)-(5,18) = "if"
110+
│ ├── predicate:
111+
│ │ @ CallNode (location: (5,19)-(5,20))
112+
│ │ ├── flags: variable_call, ignore_visibility
113+
│ │ ├── receiver: ∅
114+
│ │ ├── call_operator_loc: ∅
115+
│ │ ├── name: :d
116+
│ │ ├── message_loc: (5,19)-(5,20) = "d"
117+
│ │ ├── opening_loc: ∅
118+
│ │ ├── arguments: ∅
119+
│ │ ├── closing_loc: ∅
120+
│ │ └── block: ∅
121+
│ ├── then_keyword_loc: ∅
122+
│ ├── statements:
123+
│ │ @ StatementsNode (location: (5,0)-(5,15))
124+
│ │ ├── flags: ∅
125+
│ │ └── body: (length: 1)
126+
│ │ └── @ MultiWriteNode (location: (5,0)-(5,15))
127+
│ │ ├── flags: newline
128+
│ │ ├── lefts: (length: 1)
129+
│ │ │ └── @ LocalVariableTargetNode (location: (5,0)-(5,1))
130+
│ │ │ ├── flags: ∅
131+
│ │ │ ├── name: :a
132+
│ │ │ └── depth: 0
133+
│ │ ├── rest:
134+
│ │ │ @ ImplicitRestNode (location: (5,1)-(5,2))
135+
│ │ │ └── flags: ∅
136+
│ │ ├── rights: (length: 0)
137+
│ │ ├── lparen_loc: ∅
138+
│ │ ├── rparen_loc: ∅
139+
│ │ ├── operator_loc: (5,3)-(5,4) = "="
140+
│ │ └── value:
141+
│ │ @ RescueModifierNode (location: (5,5)-(5,15))
142+
│ │ ├── flags: ∅
143+
│ │ ├── expression:
144+
│ │ │ @ CallNode (location: (5,5)-(5,6))
145+
│ │ │ ├── flags: variable_call, ignore_visibility
146+
│ │ │ ├── receiver: ∅
147+
│ │ │ ├── call_operator_loc: ∅
148+
│ │ │ ├── name: :b
149+
│ │ │ ├── message_loc: (5,5)-(5,6) = "b"
150+
│ │ │ ├── opening_loc: ∅
151+
│ │ │ ├── arguments: ∅
152+
│ │ │ ├── closing_loc: ∅
153+
│ │ │ └── block: ∅
154+
│ │ ├── keyword_loc: (5,7)-(5,13) = "rescue"
155+
│ │ └── rescue_expression:
156+
│ │ @ CallNode (location: (5,14)-(5,15))
157+
│ │ ├── flags: variable_call, ignore_visibility
158+
│ │ ├── receiver: ∅
159+
│ │ ├── call_operator_loc: ∅
160+
│ │ ├── name: :c
161+
│ │ ├── message_loc: (5,14)-(5,15) = "c"
162+
│ │ ├── opening_loc: ∅
163+
│ │ ├── arguments: ∅
164+
│ │ ├── closing_loc: ∅
165+
│ │ └── block: ∅
166+
│ ├── subsequent: ∅
167+
│ └── end_keyword_loc: ∅
168+
└── @ IfNode (location: (7,0)-(7,23))
169+
├── flags: newline
170+
├── if_keyword_loc: (7,19)-(7,21) = "if"
171+
├── predicate:
172+
│ @ CallNode (location: (7,22)-(7,23))
173+
│ ├── flags: variable_call, ignore_visibility
174+
│ ├── receiver: ∅
175+
│ ├── call_operator_loc: ∅
176+
│ ├── name: :d
177+
│ ├── message_loc: (7,22)-(7,23) = "d"
178+
│ ├── opening_loc: ∅
179+
│ ├── arguments: ∅
180+
│ ├── closing_loc: ∅
181+
│ └── block: ∅
182+
├── then_keyword_loc: ∅
183+
├── statements:
184+
│ @ StatementsNode (location: (7,0)-(7,18))
185+
│ ├── flags: ∅
186+
│ └── body: (length: 1)
187+
│ └── @ DefNode (location: (7,0)-(7,18))
188+
│ ├── flags: newline
189+
│ ├── name: :a
190+
│ ├── name_loc: (7,4)-(7,5) = "a"
191+
│ ├── receiver: ∅
192+
│ ├── parameters: ∅
193+
│ ├── body:
194+
│ │ @ StatementsNode (location: (7,8)-(7,18))
195+
│ │ ├── flags: ∅
196+
│ │ └── body: (length: 1)
197+
│ │ └── @ RescueModifierNode (location: (7,8)-(7,18))
198+
│ │ ├── flags: ∅
199+
│ │ ├── expression:
200+
│ │ │ @ CallNode (location: (7,8)-(7,9))
201+
│ │ │ ├── flags: variable_call, ignore_visibility
202+
│ │ │ ├── receiver: ∅
203+
│ │ │ ├── call_operator_loc: ∅
204+
│ │ │ ├── name: :b
205+
│ │ │ ├── message_loc: (7,8)-(7,9) = "b"
206+
│ │ │ ├── opening_loc: ∅
207+
│ │ │ ├── arguments: ∅
208+
│ │ │ ├── closing_loc: ∅
209+
│ │ │ └── block: ∅
210+
│ │ ├── keyword_loc: (7,10)-(7,16) = "rescue"
211+
│ │ └── rescue_expression:
212+
│ │ @ CallNode (location: (7,17)-(7,18))
213+
│ │ ├── flags: variable_call, ignore_visibility
214+
│ │ ├── receiver: ∅
215+
│ │ ├── call_operator_loc: ∅
216+
│ │ ├── name: :c
217+
│ │ ├── message_loc: (7,17)-(7,18) = "c"
218+
│ │ ├── opening_loc: ∅
219+
│ │ ├── arguments: ∅
220+
│ │ ├── closing_loc: ∅
221+
│ │ └── block: ∅
222+
│ ├── locals: []
223+
│ ├── def_keyword_loc: (7,0)-(7,3) = "def"
224+
│ ├── operator_loc: ∅
225+
│ ├── lparen_loc: ∅
226+
│ ├── rparen_loc: ∅
227+
│ ├── equal_loc: (7,6)-(7,7) = "="
228+
│ └── end_keyword_loc: ∅
229+
├── subsequent: ∅
230+
└── end_keyword_loc: ∅

0 commit comments

Comments
 (0)