diff options
author | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-01-09 05:19:18 +0000 |
---|---|---|
committer | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-01-09 05:19:18 +0000 |
commit | 3cfa84d562d85f4ba8e4ad2aea08ef606c9b68a5 (patch) | |
tree | 5b0094821ca871299286f6cb8f374009a6f17371 | |
parent | 3a38b3c5d101ddd5715e9ac0f256426ce5dd58e0 (diff) | |
download | ruby-3cfa84d562d85f4ba8e4ad2aea08ef606c9b68a5.tar.gz |
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
-rw-r--r-- | parse.y | 2 | ||||
-rw-r--r-- | test/ruby/test_syntax.rb | 18 |
2 files changed, 19 insertions, 1 deletions
@@ -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; } diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index e85d6b545f..57ce169cd3 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -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 |