ruby-changes:38396
From: glass <ko1@a...>
Date: Tue, 12 May 2015 22:25:09 +0900 (JST)
Subject: [ruby-changes:38396] glass:r50477 (trunk): * enum.c (enum_to_a): fix incompatibility introduced in r50457.
glass 2015-05-12 22:24:53 +0900 (Tue, 12 May 2015) New Revision: 50477 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50477 Log: * enum.c (enum_to_a): fix incompatibility introduced in r50457. [Bug #11130] * test/ruby/test_enum.rb: test for above. Modified files: trunk/ChangeLog trunk/enum.c trunk/test/ruby/test_enum.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 50476) +++ ChangeLog (revision 50477) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue May 12 22:18:27 2015 Masaki Matsushita <glass.saga@g...> + + * enum.c (enum_to_a): fix incompatibility introduced in r50457. + [Bug #11130] + + * test/ruby/test_enum.rb: test for above. + Tue May 12 17:08:03 2015 Koichi Sasada <ko1@a...> * method.h: remove unused declaration. Index: enum.c =================================================================== --- enum.c (revision 50476) +++ enum.c (revision 50477) @@ -517,11 +517,11 @@ enum_to_a(int argc, VALUE *argv, VALUE o https://github.com/ruby/ruby/blob/trunk/enum.c#L517 { VALUE ary, size = rb_check_funcall(obj, id_size, 0, 0); - if (NIL_P(size) || size == Qundef) { - ary = rb_ary_new(); + if (FIXNUM_P(size)) { + ary = rb_ary_new_capa(NUM2LONG(size)); } else { - ary = rb_ary_new_capa(NUM2LONG(size)); + ary = rb_ary_new(); } rb_block_call(obj, id_each, argc, argv, collect_all, ary); Index: test/ruby/test_enum.rb =================================================================== --- test/ruby/test_enum.rb (revision 50476) +++ test/ruby/test_enum.rb (revision 50477) @@ -100,6 +100,36 @@ class TestEnumerable < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_enum.rb#L100 assert_equal([1, 2, 3, 1, 2], @obj.to_a) end + def test_to_a_size_symbol + sym = Object.new + class << sym + include Enumerable + def each + self + end + + def size + :size + end + end + assert_equal([], sym.to_a) + end + + def test_to_a_size_infinity + inf = Object.new + class << inf + include Enumerable + def each + self + end + + def size + Float::INFINITY + end + end + assert_equal([], inf.to_a) + end + def test_to_h obj = Object.new def obj.each(*args) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/