diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-01-25 05:21:07 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-01-25 05:21:07 +0000 |
commit | 27dfc398a8cd3b63ccc527c914dee5edd696790e (patch) | |
tree | ae95b95d1f0af5bc477ce6c340f39b4f9ab39afc | |
parent | 7b8dc95b3a450b8f20049061054df0d1fc637239 (diff) |
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]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44705 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | compile.c | 8 | ||||
-rw-r--r-- | test/ruby/test_assignment.rb | 10 |
3 files changed, 21 insertions, 3 deletions
@@ -1,3 +1,9 @@ +Sat Jan 25 14:21:06 2014 Nobuyoshi Nakada <[email protected]> + + * 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 <[email protected]> * class.c (rb_extract_keywords): treat nil keyword_hash same as 0, @@ -5332,11 +5332,13 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) 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; } diff --git a/test/ruby/test_assignment.rb b/test/ruby/test_assignment.rb index e38b20b285..df646df429 100644 --- a/test/ruby/test_assignment.rb +++ b/test/ruby/test_assignment.rb @@ -692,4 +692,14 @@ class TestAssignmentGen < Test::Unit::TestCase 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 |