Skip to content

Commit

Permalink
[FIX] Bug where block variable reset to nil in def
Browse files Browse the repository at this point in the history
If a block variable was reassigned somehwere in the def body, a bug
existed where that block variable would be set to nil with the other
local variables. This meant that the block would always be set to nil
before any def code was actually run. This commit fixes that.
  • Loading branch information
adambeynon committed Aug 5, 2013
1 parent 3236511 commit 4fb3e10
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/opal/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,7 @@ def js_def(recvr, mid, args, stmts, line, end_line, sexp)

if block_name
@scope.uses_block!
@scope.add_arg block_name
end

yielder = block_name || '$yield'
Expand Down
5 changes: 5 additions & 0 deletions spec/opal/language/block_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
proc { |a, b = 100| [a, b] }.call(:foo, :bar).should == [:foo, :bar]
proc { |a, b = 100| [a, b] }.call(:foo).should == [:foo, 100]
end

it "the block variable can be optionally overwritten without destroying original block reference" do
klass = Class.new { def foo(&block); block = 100 if false; block; end }
klass.new.foo {}.should be_kind_of(Proc)
end
end

0 comments on commit 4fb3e10

Please sign in to comment.