From 5e4606423da96c2e26b00981c22bddfce0d970bf Mon Sep 17 00:00:00 2001 From: nagachika Date: Sun, 25 Feb 2024 18:29:16 +0900 Subject: merge revision(s) f15123c34ce80f3928612befe2a9aaf4c9d27fda: [Backport #18743] Fix stack trace for rescued StopIteration --- enumerator.c | 15 +++++++++++++-- test/ruby/test_enumerator.rb | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) --- test/ruby/test_enumerator.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb index 010c1e4969..bbaa91b703 100644 --- a/test/ruby/test_enumerator.rb +++ b/test/ruby/test_enumerator.rb @@ -244,6 +244,26 @@ class TestEnumerator < Test::Unit::TestCase assert_equal(res, exc.result) end + def test_stopiteration_rescue + e = [1].each + res = e.each {} + e.next + exc0 = assert_raise(StopIteration) { e.peek } + assert_include(exc0.backtrace.first, "test_enumerator.rb:#{__LINE__-1}:") + assert_nil(exc0.cause) + assert_equal(res, exc0.result) + + exc1 = assert_raise(StopIteration) { e.next } + assert_include(exc1.backtrace.first, "test_enumerator.rb:#{__LINE__-1}:") + assert_same(exc0, exc1.cause) + assert_equal(res, exc1.result) + + exc2 = assert_raise(StopIteration) { e.next } + assert_include(exc2.backtrace.first, "test_enumerator.rb:#{__LINE__-1}:") + assert_same(exc0, exc2.cause) + assert_equal(res, exc2.result) + end + def test_next_values o = Object.new def o.each -- cgit v1.2.3