ruby-changes:27670
From: naruse <ko1@a...>
Date: Mon, 11 Mar 2013 18:51:23 +0900 (JST)
Subject: [ruby-changes:27670] naruse:r39722 (trunk): * enumerator.c (enumerator_with_index): try to convert given offset to
naruse 2013-03-11 18:47:15 +0900 (Mon, 11 Mar 2013) New Revision: 39722 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39722 Log: * enumerator.c (enumerator_with_index): try to convert given offset to integer. fix bug introduced in r39594. Modified files: trunk/ChangeLog trunk/enumerator.c trunk/test/ruby/test_enumerator.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 39721) +++ ChangeLog (revision 39722) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Mar 11 18:45:09 2013 NARUSE, Yui <naruse@r...> + + * enumerator.c (enumerator_with_index): try to convert given offset to + integer. fix bug introduced in r39594. + Mon Mar 11 17:27:57 2013 NARUSE, Yui <naruse@r...> * test/ruby/envutil.rb (EnvUtil.with_default_external): add for Index: enumerator.c =================================================================== --- enumerator.c (revision 39721) +++ enumerator.c (revision 39722) @@ -494,6 +494,8 @@ enumerator_with_index(int argc, VALUE *a https://github.com/ruby/ruby/blob/trunk/enumerator.c#L494 RETURN_SIZED_ENUMERATOR(obj, argc, argv, enumerator_size); if (NIL_P(memo)) memo = INT2FIX(0); + else + memo = rb_to_int(memo); return enumerator_block_call(obj, enumerator_with_index_i, (VALUE)&memo); } Index: test/ruby/test_enumerator.rb =================================================================== --- test/ruby/test_enumerator.rb (revision 39721) +++ test/ruby/test_enumerator.rb (revision 39722) @@ -112,6 +112,18 @@ class TestEnumerator < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_enumerator.rb#L112 assert_equal([[1,s],[2,s+1],[3,s+2]], @obj.to_enum(:foo, 1, 2, 3).with_index(s).to_a, bug8010) end + def test_with_index_nonnum_offset + bug8010 = '[ruby-dev:47131] [Bug #8010]' + s = Object.new + def s.to_int; 1 end + assert_equal([[1,1],[2,2],[3,3]], @obj.to_enum(:foo, 1, 2, 3).with_index(s).to_a, bug8010) + end + + def test_with_index_string_offset + bug8010 = '[ruby-dev:47131] [Bug #8010]' + assert_raise(TypeError, bug8010){ @obj.to_enum(:foo, 1, 2, 3).with_index('1').to_a } + end + def test_with_object obj = [0, 1] ret = (1..10).each.with_object(obj) {|i, memo| -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/