Permalink
Browse files

parse.y: rescue/else/ensure in do-end

* parse.y (do_body): allow rescue/else/ensure inside do/end
  blocks.  [Feature #12906]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57376 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
nobu committed Jan 19, 2017
1 parent f34d0ba commit 0ec889d7ed34f80b534dfc7a93bdd3175aba9ff9
Showing with 70 additions and 1 deletion.
  1. +2 −0 NEWS
  2. +1 −1 parse.y
  3. +67 −0 test/ruby/test_syntax.rb
View
2 NEWS
@@ -16,6 +16,8 @@ with all sufficient information, see the ChangeLog file or Redmine
* Top-level constant look-up is removed. [Feature #11547]
* rescue/else/ensure are allowed inside do/end blocks. [Feature #12906]
=== Core classes updates (outstanding ones only)
=== Stdlib updates (outstanding ones only)
View
@@ -3763,7 +3763,7 @@ brace_body : {$<vars>$ = dyna_push();}
do_body : {$<vars>$ = dyna_push();}
{$<val>$ = cmdarg_stack; CMDARG_SET(0);}
opt_block_param compstmt
opt_block_param bodystmt
{
$$ = new_do_body($3, $4);
dyna_pop($<vars>1);
View
@@ -979,6 +979,73 @@ def test_invalid_jump
assert_in_out_err(%w[-e redo], "", [], /^-e:1: /)
end
def test_rescue_do_end_raised
result = []
assert_raise(RuntimeError) do
eval("#{<<-"begin;"}\n#{<<-"end;"}")
begin;
tap do
result << :begin
raise "An exception occured!"
ensure
result << :ensure
end
end;
end
assert_equal([:begin, :ensure], result)
end
def test_rescue_do_end_rescued
result = []
assert_nothing_raised(RuntimeError) do
eval("#{<<-"begin;"}\n#{<<-"end;"}")
begin;
tap do
result << :begin
raise "An exception occured!"
rescue
result << :rescue
else
result << :else
ensure
result << :ensure
end
end;
end
assert_equal([:begin, :rescue, :ensure], result)
end
def test_rescue_do_end_no_raise
result = []
assert_nothing_raised(RuntimeError) do
eval("#{<<-"begin;"}\n#{<<-"end;"}")
begin;
tap do
result << :begin
rescue
result << :rescue
else
result << :else
ensure
result << :ensure
end
end;
end
assert_equal([:begin, :else, :ensure], result)
end
def test_rescue_do_end_ensure_result
result = eval("#{<<-"begin;"}\n#{<<-"end;"}")
begin;
proc do
:begin
ensure
:ensure
end.call
end;
assert_equal(:begin, result)
end
private
def not_label(x) @result = x; @not_label ||= nil end

0 comments on commit 0ec889d

Please sign in to comment.