Skip to content

Commit 51607af

Browse files
nobutmm1
authored andcommitted
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 ruby#9448] git-svn-id: svn+ssh://svn.ruby-lang.org/ruby/trunk@44705 b2dd03c8-39d4-4d8f-98ff-823fe69b080e Conflicts: ChangeLog compile.c
1 parent 42219c2 commit 51607af

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

compile.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5329,11 +5329,13 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
53295329
iseq_add_mark_object(iseq, str);
53305330
COMPILE(ret, "recv", node->nd_recv);
53315331
COMPILE(ret, "value", node->nd_args->nd_next->nd_head);
5332+
if (!poped) {
5333+
ADD_INSN(ret, line, swap);
5334+
ADD_INSN1(ret, line, topn, INT2FIX(1));
5335+
}
53325336
ADD_INSN2(ret, line, opt_aset_str,
53335337
new_callinfo(iseq, idASET, 2, 0, 0), str);
5334-
if (poped) {
5335-
ADD_INSN(ret, line, pop);
5336-
}
5338+
ADD_INSN(ret, line, pop);
53375339
break;
53385340
}
53395341

test/ruby/test_assignment.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,4 +692,14 @@ def test_assignment
692692
check(assign)
693693
}
694694
end
695+
696+
def test_optimized_aset
697+
bug9448 = Class.new do
698+
def []=(key, new_value)
699+
'[ruby-core:60071] [Bug #9448]'
700+
end
701+
end
702+
o = bug9448.new
703+
assert_equal("ok", o['current'] = "ok")
704+
end
695705
end

0 commit comments

Comments
 (0)