From d1ff2cf18af95b103f16e7036409d228e6512958 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Mon, 15 Aug 2022 14:09:54 -0400 Subject: [PATCH] Consume end tokens on begins with rescue or ensure Co-authored-by: Kevin Newton --- lib/syntax_tree/parser.rb | 3 +-- test/fixtures/def_endless.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/syntax_tree/parser.rb b/lib/syntax_tree/parser.rb index 8a64bc32..3824b6b3 100644 --- a/lib/syntax_tree/parser.rb +++ b/lib/syntax_tree/parser.rb @@ -717,8 +717,7 @@ def on_begin(bodystmt) else keyword = find_token(Kw, "begin") end_location = - if bodystmt.rescue_clause || bodystmt.ensure_clause || - bodystmt.else_clause + if bodystmt.else_clause bodystmt.location else find_token(Kw, "end").location diff --git a/test/fixtures/def_endless.rb b/test/fixtures/def_endless.rb index dbac88bb..15ea518b 100644 --- a/test/fixtures/def_endless.rb +++ b/test/fixtures/def_endless.rb @@ -18,3 +18,11 @@ def self.foo() = bar def self.foo = bar % # >= 3.1.0 def self.foo = bar baz +% +begin + true +rescue StandardError + false +end + +def foo? = true