From 94ee3e7e0207eedac81b30444f72d5b51a7c2230 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 7 May 2009 07:40:11 +0000 Subject: [PATCH] * array.c (rb_ary_flatten_bang): returns nil if nothing changed. a patch from Marc-Andre Lafortune in [ruby-core:23382]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23361 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ array.c | 2 +- test/ruby/test_array.rb | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index d27a168ac7..e2ae91272b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu May 7 16:40:09 2009 Nobuyoshi Nakada + + * array.c (rb_ary_flatten_bang): returns nil if nothing changed. + a patch from Marc-Andre Lafortune in [ruby-core:23382]. + Thu May 7 14:26:14 2009 Nobuyoshi Nakada * array.c (rb_ary_sample): negative sample number is invalid. diff --git a/array.c b/array.c index 4eeae43391..034aa7fcf0 100644 --- a/array.c +++ b/array.c @@ -3338,7 +3338,7 @@ rb_ary_flatten_bang(int argc, VALUE *argv, VALUE ary) rb_scan_args(argc, argv, "01", &lv); if (!NIL_P(lv)) level = NUM2INT(lv); - if (level == 0) return ary; + if (level == 0) return Qnil; result = flatten(ary, level, &mod); if (mod == 0) return Qnil; diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index a20c6b23cd..7b0039310a 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -736,11 +736,14 @@ class TestArray < Test::Unit::TestCase a5 = @cls[ a1, @cls[], a3 ] assert_equal(@cls[1, 2, 3, 4, 5, 6], a5.flatten!) + assert_nil(a5.flatten!(0), '[ruby-core:23382]') assert_equal(@cls[1, 2, 3, 4, 5, 6], a5) assert_equal(@cls[], @cls[].flatten) assert_equal(@cls[], @cls[@cls[@cls[@cls[],@cls[]],@cls[@cls[]],@cls[]],@cls[@cls[@cls[]]]].flatten) + + assert_nil(@cls[].flatten!(0), '[ruby-core:23382]') end def test_flatten_with_callcc