diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-10-22 00:52:59 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-10-22 00:52:59 +0000 |
commit | d506a3521c7ebec78bf1aa2f0015c6cafb785f99 (patch) | |
tree | 21dd3bba19b8f6453c4936060b6b1b12f9a7cc11 | |
parent | e1ff9d68abc8bfa2fe6d02f53e9bd09d022a3a97 (diff) | |
download | ruby-d506a3521c7ebec78bf1aa2f0015c6cafb785f99.tar.gz |
compile.c: order with splatting
* compile.c (setup_args): duplicate splatting array if more
arguments present to obey left-to-right execution order.
[ruby-core:77701] [Bug# 12860]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56469 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | compile.c | 4 | ||||
-rw-r--r-- | test/ruby/test_call.rb | 8 |
3 files changed, 16 insertions, 2 deletions
@@ -1,3 +1,9 @@ +Sat Oct 22 09:52:57 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * compile.c (setup_args): duplicate splatting array if more + arguments present to obey left-to-right execution order. + [ruby-core:77701] [Bug# 12860] + Fri Oct 21 16:44:44 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> * dir.c (do_opendir): retry after GC when the limit for open file @@ -3741,7 +3741,7 @@ setup_args(rb_iseq_t *iseq, LINK_ANCHOR *args, NODE *argn, unsigned int *flag, s switch (nd_type(argn)) { case NODE_SPLAT: { COMPILE(args, "args (splat)", argn->nd_head); - ADD_INSN1(args, nd_line(argn), splatarray, Qfalse); + ADD_INSN1(args, nd_line(argn), splatarray, nsplat ? Qtrue : Qfalse); argc = INT2FIX(1); nsplat++; *flag |= VM_CALL_ARGS_SPLAT; @@ -3755,7 +3755,7 @@ setup_args(rb_iseq_t *iseq, LINK_ANCHOR *args, NODE *argn, unsigned int *flag, s INIT_ANCHOR(tmp); COMPILE(tmp, "args (cat: splat)", argn->nd_body); if (nd_type(argn) == NODE_ARGSCAT) { - ADD_INSN1(tmp, nd_line(argn), splatarray, Qfalse); + ADD_INSN1(tmp, nd_line(argn), splatarray, nsplat ? Qtrue : Qfalse); } else { ADD_INSN1(tmp, nd_line(argn), newarray, INT2FIX(1)); diff --git a/test/ruby/test_call.rb b/test/ruby/test_call.rb index fb79eadb64..4496d78210 100644 --- a/test/ruby/test_call.rb +++ b/test/ruby/test_call.rb @@ -90,4 +90,12 @@ class TestCall < Test::Unit::TestCase h[:foo] = nil } end + + def test_call_splat_order + bug12860 = '[ruby-core:77701] [Bug# 12860]' + ary = [1, 2] + assert_equal([1, 2, 1], aaa(*ary, ary.shift), bug12860) + ary = [1, 2] + assert_equal([0, 1, 2, 1], aaa(0, *ary, ary.shift), bug12860) + end end |