diff options
author | Jeremy Evans <code@jeremyevans.net> | 2021-09-30 13:18:14 -0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-30 15:18:14 -0700 |
commit | 1f5f8a187adb746b01cc95c3f29a0a355f513374 (patch) | |
tree | 9d907b527d60b89f4c9d6402b1bdabb8aec7abf0 /test/ruby/test_refinement.rb | |
parent | a55a5fc68426ed701dace6bc166d18de06d8dcb2 (diff) | |
download | ruby-1f5f8a187adb746b01cc95c3f29a0a355f513374.tar.gz |
Make Array#min/max optimization respect refined methods
Pass in ec to vm_opt_newarray_{max,min}. Avoids having to
call GET_EC inside the functions, for better performance.
While here, add a test for Array#min/max being redefined to
test_optimization.rb.
Fixes [Bug #18180]
Diffstat (limited to 'test/ruby/test_refinement.rb')
-rw-r--r-- | test/ruby/test_refinement.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb index a623432cf1..96baab03ee 100644 --- a/test/ruby/test_refinement.rb +++ b/test/ruby/test_refinement.rb @@ -2537,6 +2537,25 @@ class TestRefinement < Test::Unit::TestCase assert_equal(:second, klass.new.foo) end + class Bug18180 + module M + refine Array do + def min; :min; end + def max; :max; end + end + end + + using M + + def t + [[1+0, 2, 4].min, [1, 2, 4].min, [1+0, 2, 4].max, [1, 2, 4].max] + end + end + + def test_refine_array_min_max + assert_equal([:min, :min, :max, :max], Bug18180.new.t) + end + class Bug17822 module Ext refine(Bug17822) do |