Skip to content

Commit 545d07d

Browse files
committed
Fix parser translator rescue location with semicolon body
There are a few other locations that should be included in that check. I think the end location must always be present but I left it in to be safe (maybe implicit begin somehow?)
1 parent 6e66de3 commit 545d07d

File tree

3 files changed

+256
-182
lines changed

3 files changed

+256
-182
lines changed

lib/prism/translation/parser/compiler.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,14 @@ def visit_begin_node(node)
203203
if (rescue_clause = node.rescue_clause)
204204
begin
205205
find_start_offset = (rescue_clause.reference&.location || rescue_clause.exceptions.last&.location || rescue_clause.keyword_loc).end_offset
206-
find_end_offset = (rescue_clause.statements&.location&.start_offset || rescue_clause.subsequent&.location&.start_offset || (find_start_offset + 1))
206+
find_end_offset = (
207+
rescue_clause.statements&.location&.start_offset ||
208+
rescue_clause.subsequent&.location&.start_offset ||
209+
node.else_clause&.location&.start_offset ||
210+
node.ensure_clause&.location&.start_offset ||
211+
node.end_keyword_loc&.start_offset ||
212+
find_start_offset + 1
213+
)
207214

208215
rescue_bodies << builder.rescue_body(
209216
token(rescue_clause.keyword_loc),

test/prism/fixtures/begin_rescue.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ begin; a; rescue; b; else; c; end
22

33
begin; a; rescue; b; else; c; ensure; d; end
44

5+
begin; rescue ; end
6+
7+
begin; rescue ; ensure ; end
8+
9+
begin; rescue ; else ; end
10+
511
begin
612
a
713
end

0 commit comments

Comments
 (0)