ruby-changes:32626
From: nobu <ko1@a...>
Date: Sat, 25 Jan 2014 14:21:14 +0900 (JST)
Subject: [ruby-changes:32626] nobu:r44705 (trunk): compile.c: assignment result of aset_with
nobu 2014-01-25 14:21:07 +0900 (Sat, 25 Jan 2014) New Revision: 44705 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44705 Log: compile.c: assignment result of aset_with * compile.c (iseq_compile_each): result of assignment should be its rhs instead of returned value from a method. [ruby-core:60071] [Bug #9448] Modified files: trunk/ChangeLog trunk/compile.c trunk/test/ruby/test_assignment.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 44704) +++ ChangeLog (revision 44705) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Jan 25 14:21:06 2014 Nobuyoshi Nakada <nobu@r...> + + * compile.c (iseq_compile_each): result of assignment should be + its rhs instead of returned value from a method. + [ruby-core:60071] [Bug #9448] + Sat Jan 25 11:16:19 2014 Nobuyoshi Nakada <nobu@r...> * class.c (rb_extract_keywords): treat nil keyword_hash same as 0, Index: compile.c =================================================================== --- compile.c (revision 44704) +++ compile.c (revision 44705) @@ -5332,11 +5332,13 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L5332 iseq_add_mark_object(iseq, str); COMPILE(ret, "recv", node->nd_recv); COMPILE(ret, "value", node->nd_args->nd_next->nd_head); + if (!poped) { + ADD_INSN(ret, line, swap); + ADD_INSN1(ret, line, topn, INT2FIX(1)); + } ADD_INSN2(ret, line, opt_aset_with, new_callinfo(iseq, idASET, 2, 0, 0), str); - if (poped) { - ADD_INSN(ret, line, pop); - } + ADD_INSN(ret, line, pop); break; } Index: test/ruby/test_assignment.rb =================================================================== --- test/ruby/test_assignment.rb (revision 44704) +++ test/ruby/test_assignment.rb (revision 44705) @@ -692,4 +692,14 @@ class TestAssignmentGen < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/ruby/test_assignment.rb#L692 check(assign) } end + + def test_optimized_aset + bug9448 = Class.new do + def []=(key, new_value) + '[ruby-core:60071] [Bug #9448]' + end + end + o = bug9448.new + assert_equal("ok", o['current'] = "ok") + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/