Allow -> do rescue; end as well as proc do rescue; end

https://twitter.com/takiuchi/status/950593389963051008

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61710 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2018-01-09 05:19:18 +00:00
parent 3a38b3c5d1
commit 3cfa84d562
2 changed files with 19 additions and 1 deletions

View File

@ -3453,7 +3453,7 @@ lambda_body : tLAMBEG compstmt '}'
token_info_pop("}");
$$ = $2;
}
| keyword_do_LAMBDA compstmt k_end
| keyword_do_LAMBDA bodystmt k_end
{
$$ = $2;
}

View File

@ -1128,6 +1128,24 @@ eom
assert_equal(:begin, result)
end
def test_rescue_do_end_ensure_in_lambda
result = []
eval("#{<<-"begin;"}\n#{<<-"end;"}")
begin;
-> do
result << :begin
raise "An exception occurred!"
rescue
result << :rescue
else
result << :else
ensure
result << :ensure
end.call
end;
assert_equal([:begin, :rescue, :ensure], result)
end
def test_return_in_loop
obj = Object.new
def obj.test