From cd4f5b13228879d954fa97b6aa479c4a5ef4fb0a Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 31 Aug 2021 16:58:29 -0700 Subject: Guard array when appending This prevents early collection of the array. The GC doesn't see the array on the stack when Ruby is compiled with optimizations enabled [ruby-core:105099] [Bug #18140] --- test/ruby/test_array.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index 59e1ad463c..8de51c159d 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -654,6 +654,12 @@ class TestArray < Test::Unit::TestCase assert_raise(TypeError) { [0].concat(:foo) } assert_raise(FrozenError) { [0].freeze.concat(:foo) } + + a = @cls[nil] + def (x = Object.new).to_ary; Array.new(10) {nil} << :ok; end + EnvUtil.under_gc_stress {a.concat(x)} + GC.start + assert_equal(:ok, a.last) end def test_count -- cgit v1.2.3