From 868684096079f3e786df517714fe6d795c4647b6 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 18 Sep 2009 07:15:06 +0000 Subject: * compile.c (iseq_compile_each), parse.y (stmt, arg): arg_concat() on op_asgn was inversed. [ruby-core:25629] [Bug #2050] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24999 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ compile.c | 8 ++++---- parse.y | 4 ++-- test/ruby/test_assignment.rb | 8 ++++++++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2db469c1f2..d24cf34b12 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Sep 18 16:15:04 2009 Nobuyoshi Nakada + + * compile.c (iseq_compile_each), parse.y (stmt, arg): arg_concat() + on op_asgn was inversed. [ruby-core:25629] [Bug #2050] + Fri Sep 18 16:06:27 2009 Nobuyoshi Nakada * dir.c (GlobPathValue): glob allows null bytes as separators. diff --git a/compile.c b/compile.c index 3999e69de6..0b4eb0d061 100644 --- a/compile.c +++ b/compile.c @@ -3760,9 +3760,9 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) ADD_INSN(ret, nd_line(node), putnil); } COMPILE(ret, "NODE_OP_ASGN1 recv", node->nd_recv); - if (nd_type(node->nd_args->nd_body) != NODE_ZARRAY) { + if (nd_type(node->nd_args->nd_head) != NODE_ZARRAY) { INIT_ANCHOR(args); - argc = setup_args(iseq, args, node->nd_args->nd_body, &flag); + argc = setup_args(iseq, args, node->nd_args->nd_head, &flag); ADD_SEQ(ret, args); } else { @@ -3795,7 +3795,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) } ADD_INSN(ret, nd_line(node), pop); - COMPILE(ret, "NODE_OP_ASGN1 args->head: ", node->nd_args->nd_head); + COMPILE(ret, "NODE_OP_ASGN1 args->body: ", node->nd_args->nd_body); if (!poped) { ADD_INSN1(ret, nd_line(node), setn, FIXNUM_INC(argc, 2)); } @@ -3819,7 +3819,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) ADD_LABEL(ret, lfin); } else { - COMPILE(ret, "NODE_OP_ASGN1 args->head: ", node->nd_args->nd_head); + COMPILE(ret, "NODE_OP_ASGN1 args->body: ", node->nd_args->nd_body); ADD_SEND(ret, nd_line(node), ID2SYM(id), INT2FIX(1)); if (!poped) { ADD_INSN1(ret, nd_line(node), setn, FIXNUM_INC(argc, 2)); diff --git a/parse.y b/parse.y index eca19d05d2..fab4e3990b 100644 --- a/parse.y +++ b/parse.y @@ -1050,7 +1050,7 @@ stmt : keyword_alias fitem {lex_state = EXPR_FNAME;} fitem value_expr($6); if (!$3) $3 = NEW_ZARRAY(); - args = arg_concat($6, $3); + args = arg_concat($3, $6); if ($5 == tOROP) { $5 = 0; } @@ -1884,7 +1884,7 @@ arg : lhs '=' arg value_expr($6); if (!$3) $3 = NEW_ZARRAY(); - args = arg_concat($6, $3); + args = arg_concat($3, $6); if ($5 == tOROP) { $5 = 0; } diff --git a/test/ruby/test_assignment.rb b/test/ruby/test_assignment.rb index b82cee81d1..e38b20b285 100644 --- a/test/ruby/test_assignment.rb +++ b/test/ruby/test_assignment.rb @@ -77,6 +77,14 @@ class TestAssignment < Test::Unit::TestCase a,b,*c = *[*[]]; assert_equal([nil,nil,[]], [a,b,c]) a,b,*c = *[*[1]]; assert_equal([1,nil,[]], [a,b,c]) a,b,*c = *[*[1,2]]; assert_equal([1,2,[]], [a,b,c]) + + bug2050 = '[ruby-core:25629]' + a = Hash.new {[]} + b = [1, 2] + assert_equal([1, 2, 3], a[:x] += [*b, 3], bug2050) + assert_equal([1, 2, 3], a[:x], bug2050) + assert_equal([1, 2, 3, [1, 2, 3]], a[:x] <<= [*b, 3], bug2050) + assert_equal([1, 2, 3, [1, 2, 3]], a[:x], bug2050) end def test_yield -- cgit v1.2.3