From c27bd84806454f4627d8957a87b6186da1aab089 Mon Sep 17 00:00:00 2001 From: nagachika Date: Mon, 2 Dec 2013 14:48:50 +0000 Subject: merge revision(s) 43929: [Backport #9178] * enumerator.c (enumerator_with_index): should not store local variable address to memoise the arguments. it is invalidated after the return. [ruby-core:58692] [Bug #9178] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@43961 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_enumerator.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test') diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb index 8843d8d732..9e2502a965 100644 --- a/test/ruby/test_enumerator.rb +++ b/test/ruby/test_enumerator.rb @@ -112,6 +112,16 @@ 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_dangling_memo + bug9178 = '[ruby-core:58692] [Bug #9178]' + assert_separately([], <<-"end;") + bug = "#{bug9178}" + e = [1].to_enum(:chunk).with_index {|c,i| i == 5} + assert_kind_of(Enumerator, e) + assert_equal([false, [1]], e.to_a[0], bug) + end; + end + def test_with_object obj = [0, 1] ret = (1..10).each.with_object(obj) {|i, memo| -- cgit v1.2.3