Skip to content

Commit

Permalink
Fix code generation for op_asgn_1 calls (foo[bar] += 10)
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Jan 6, 2014
1 parent bafc36a commit a62a443
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -92,6 +92,8 @@
* Support any Tilt template for `index_path` in `Opal::Server`. All index
files are now run through `Tilt` (now supports haml etc).

* Fix code generation of `op_asgn_1` calls (foo[val] += 10).

## 0.5.5 2013-11-25

* Fix regression: add `%i[foo bar]` style words back to lexer
Expand Down
2 changes: 1 addition & 1 deletion lib/opal/nodes/call_special.rb
Expand Up @@ -77,7 +77,7 @@ def compile_operator
with_temp do |a| # args
with_temp do |r| # recv
cur = s(:call, s(:js_tmp, r), :[], s(:arglist, s(:js_tmp, a)))
rhs = s(:call, cur, :+, s(:arglist, self.rhs))
rhs = s(:call, cur, op.to_sym, s(:arglist, self.rhs))
call = s(:call, s(:js_tmp, r), :[]=, s(:arglist, s(:js_tmp, a), rhs))

push "(#{a} = ", expr(first_arg), ", #{r} = ", expr(lhs)
Expand Down
13 changes: 13 additions & 0 deletions spec/opal/core/runtime/operator_call_spec.rb
@@ -0,0 +1,13 @@
require 'spec_helper'

describe "Operator calls" do
before { @obj = {:value => 10} }

it "compiles as a normal send method call" do
@obj[:value] += 15
@obj[:value].should == 25

@obj[:value] -= 23
@obj[:value].should == 2
end
end

0 comments on commit a62a443

Please sign in to comment.