Skip to content

Commit

Permalink
Handle assignement of exceptions to instance variables
Browse files Browse the repository at this point in the history
  • Loading branch information
mvz committed Feb 6, 2014
1 parent 2a56b8e commit 0a1daff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/ripper_ruby_parser/sexp_handlers/blocks.rb
Expand Up @@ -69,9 +69,7 @@ def process_rescue exp
end

if evar
evar = process(evar)[1]
easgn = s(:lasgn, evar, s(:gvar, :$!))
arr << easgn
arr << create_assignment_sub_type(process(evar), s(:gvar, :$!))
end

s(
Expand Down
10 changes: 10 additions & 0 deletions test/unit/parser_blocks_test.rb
Expand Up @@ -91,6 +91,16 @@
s(:call, nil, :baz)))
end

it "works with assignment of the exception to an instance variable" do
"begin; foo; rescue => @bar; baz; end".
must_be_parsed_as s(:rescue,
s(:call, nil, :foo),
s(:resbody,
s(:array,
s(:iasgn, :@bar, s(:gvar, :$!))),
s(:call, nil, :baz)))
end

it "works with empty main and rescue bodies" do
"begin; rescue; end".
must_be_parsed_as s(:rescue,
Expand Down

0 comments on commit 0a1daff

Please sign in to comment.