From 11edc286d837f66b37433e7d51c8b8f500e1be84 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Thu, 15 Jan 2026 20:32:20 +0900 Subject: Make `Array#map` and `Array#select` more tolerant Only when YJIT is enabled, the redefinition of `Array#<<` affects these methods. --- test/ruby/test_array.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index d93b86e795..04e15b6d87 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -1336,6 +1336,28 @@ class TestArray < Test::Unit::TestCase assert_equal(@cls[@cls[1,2], nil, 'dog', 'cat'], a.prepend(@cls[1, 2])) end + def test_tolerant_to_redefinition + *code = __FILE__, __LINE__+1, "#{<<-"{#"}\n#{<<-'};'}" + {# + module M + def <<(a) + super(a * 2) + end + end + class Array; prepend M; end + ary = [*1..10] + mapped = ary.map {|i| i} + selected = ary.select {true} + module M + remove_method :<< + end + assert_equal(ary, mapped) + assert_equal(ary, selected) + }; + assert_separately(%w[--disable-yjit], *code) + assert_separately(%w[--enable-yjit], *code) + end + def test_push a = @cls[1, 2, 3] assert_equal(@cls[1, 2, 3, 4, 5], a.push(4, 5)) -- cgit v1.2.3