diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-03-11 09:47:15 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-03-11 09:47:15 +0000 |
commit | 5f257cf403a0316ee005b5cc476b04dbf9ca86ec (patch) | |
tree | 733f6877361177c8ceb95c6ed169c5dc4b49c064 | |
parent | 7590de68e2102d586a1fb4e34642643b3c731269 (diff) | |
download | ruby-5f257cf403a0316ee005b5cc476b04dbf9ca86ec.tar.gz |
* enumerator.c (enumerator_with_index): try to convert given offset to
integer. fix bug introduced in r39594.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39722 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | enumerator.c | 2 | ||||
-rw-r--r-- | test/ruby/test_enumerator.rb | 12 |
3 files changed, 19 insertions, 0 deletions
@@ -1,3 +1,8 @@ +Mon Mar 11 18:45:09 2013 NARUSE, Yui <naruse@ruby-lang.org> + + * 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@ruby-lang.org> * test/ruby/envutil.rb (EnvUtil.with_default_external): add for diff --git a/enumerator.c b/enumerator.c index 022690a2a3..3aa0d2ea78 100644 --- a/enumerator.c +++ b/enumerator.c @@ -494,6 +494,8 @@ enumerator_with_index(int argc, VALUE *argv, VALUE obj) 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); } diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb index 8843d8d732..40dddc066d 100644 --- a/test/ruby/test_enumerator.rb +++ b/test/ruby/test_enumerator.rb @@ -112,6 +112,18 @@ class TestEnumerator < Test::Unit::TestCase 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| |