summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-11-27 02:54:02 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-11-27 02:54:02 +0000
commitdd1e757adb87340ac13354c3228a5c2e1c0b1bb4 (patch)
tree6f0977f9a84bc4d0ac8030c7458ff70a440b5485
parentadc25ed110871abb5ba13fea789ee911dd8ce348 (diff)
merges r24761 and r24999 from trunk into ruby_1_9_1.
-- * compile.c (iseq_compile_each): op_asgn to aref should return rhs. [ruby-core:25387] -- * 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/branches/ruby_1_9_1@25940 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog10
-rw-r--r--compile.c43
-rw-r--r--parse.y4
-rw-r--r--test/ruby/test_assignment.rb8
-rw-r--r--test/ruby/test_basicinstructions.rb25
-rw-r--r--version.h2
6 files changed, 74 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index 6e68c61d7a..1bcb1a0f42 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Fri Sep 18 16:15:04 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * compile.c (iseq_compile_each), parse.y (stmt, arg): arg_concat()
+ on op_asgn was inversed. [ruby-core:25629] [Bug #2050]
+
+Sat Sep 5 15:21:13 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * compile.c (iseq_compile_each): op_asgn to aref should return rhs.
+ [ruby-core:25387]
+
Sun Feb 15 03:50:21 2009 Yusuke Endoh <mame@tsg.ne.jp>
* hash.c (rb_hash): always return a fixnum value because a return
diff --git a/compile.c b/compile.c
index bc11cd282a..650424a70e 100644
--- a/compile.c
+++ b/compile.c
@@ -3736,13 +3736,16 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
/*
* a[x] (op)= y
*
- * eval a # a
- * eval x # a x
- * dupn 2 # a x a x
- * send :[] # a x a[x]
- * eval y # a x a[x] y
- * send op # a x a[x]+y
- * send []= # ret
+ * nil # nil
+ * eval a # nil a
+ * eval x # nil a x
+ * dupn 2 # nil a x a x
+ * send :[] # nil a x a[x]
+ * eval y # nil a x a[x] y
+ * send op # nil a x ret
+ * setn 3 # ret a x ret
+ * send []= # ret ?
+ * pop # ret
*/
/*
@@ -3753,10 +3756,13 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
* nd_mid
*/
+ if (!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 {
@@ -3791,7 +3797,10 @@ 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, INT2FIX(3));
+ }
if (flag & VM_CALL_ARGS_SPLAT_BIT) {
ADD_INSN1(ret, nd_line(node), newarray, INT2FIX(1));
ADD_INSN(ret, nd_line(node), concatarray);
@@ -3802,15 +3811,21 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
ADD_SEND_R(ret, nd_line(node), ID2SYM(idASET),
INT2FIX(FIX2INT(argc) + 1), Qfalse, LONG2FIX(flag));
}
+ ADD_INSN(ret, nd_line(node), pop);
ADD_INSNL(ret, nd_line(node), jump, lfin);
ADD_LABEL(ret, label);
- ADD_INSN1(ret, nd_line(node), setn, INT2FIX(FIX2INT(argc) + 1));
- ADD_INSN1(ret, nd_line(node), adjuststack, INT2FIX(FIX2INT(argc) + 1));
+ if (!poped) {
+ ADD_INSN1(ret, nd_line(node), setn, INT2FIX(FIX2INT(argc) + 2));
+ }
+ ADD_INSN1(ret, nd_line(node), adjuststack, INT2FIX(FIX2INT(argc) + 2));
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, INT2FIX(FIX2INT(argc) + 2));
+ }
if (flag & VM_CALL_ARGS_SPLAT_BIT) {
ADD_INSN1(ret, nd_line(node), newarray, INT2FIX(1));
ADD_INSN(ret, nd_line(node), concatarray);
@@ -3821,9 +3836,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
ADD_SEND_R(ret, nd_line(node), ID2SYM(idASET),
INT2FIX(FIX2INT(argc) + 1), Qfalse, LONG2FIX(flag));
}
- }
- if (poped) {
ADD_INSN(ret, nd_line(node), pop);
}
diff --git a/parse.y b/parse.y
index 9ea945abf9..80a67e1147 100644
--- a/parse.y
+++ b/parse.y
@@ -1100,7 +1100,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;
}
@@ -1935,7 +1935,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
diff --git a/test/ruby/test_basicinstructions.rb b/test/ruby/test_basicinstructions.rb
index 90b034a90b..eab9afc50c 100644
--- a/test/ruby/test_basicinstructions.rb
+++ b/test/ruby/test_basicinstructions.rb
@@ -505,6 +505,14 @@ class TestBasicInstructions < Test::Unit::TestCase
:Bug1996
end
Bug1996 = '[ruby-dev:39163], [ruby-core:25143]'
+ def [](i)
+ @x
+ end
+ def []=(i, x)
+ @x = x
+ :Bug2050
+ end
+ Bug2050 = '[ruby-core:25387]'
end
def test_opassign2_1
@@ -575,6 +583,23 @@ class TestBasicInstructions < Test::Unit::TestCase
assert_equal 4, a[0]
end
+ def test_opassign1_2
+ x = OP.new
+ x[0] = nil
+ assert_equal 1, x[0] ||= 1, OP::Bug2050
+ assert_equal 1, x[0]
+ assert_equal 2, x[0] &&= 2, OP::Bug2050
+ assert_equal 2, x[0]
+ assert_equal 2, x[0] ||= 3, OP::Bug2050
+ assert_equal 2, x[0]
+ assert_equal 4, x[0] &&= 4, OP::Bug2050
+ assert_equal 4, x[0]
+ assert_equal 5, x[0] += 1, OP::Bug2050
+ assert_equal 5, x[0]
+ assert_equal 4, x[0] -= 1, OP::Bug2050
+ assert_equal 4, x[0]
+ end
+
def test_backref
/re/ =~ 'not match'
assert_nil $~
diff --git a/version.h b/version.h
index 9cc7030bca..288ad26dde 100644
--- a/version.h
+++ b/version.h
@@ -1,5 +1,5 @@
#define RUBY_VERSION "1.9.1"
-#define RUBY_PATCHLEVEL 341
+#define RUBY_PATCHLEVEL 342
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 9
#define RUBY_VERSION_TEENY 1