Project

General

Profile

Actions

Bug #18180

closed

opt_newarray_min/max instructions ignore refined methods

Added by wanabe (_ wanabe) about 1 month ago. Updated 25 days ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 3.1.0dev (2021-09-20T10:07:58Z master cb8434563d) [x86_64-linux]
[ruby-core:105352]

Description

$ ./miniruby -ve 'module M; refine Array do; def max; :max; end; def min; :min; end; end; end; using M; p [1 + 0, 2, 3].max, [1 + 0, 2, 3].min'
ruby 3.1.0dev (2021-09-20T10:07:58Z master cb8434563d) [x86_64-linux]
3
1

I expected :max and :min to be returned.

If I avoid the opt_newarray_min/max instruction, the behavior will be as expected.

$ ./miniruby -ve 'module M; refine Array do; def max; :max; end; def min; :min; end; end; end; using M; p [1, 2, 3].max, [1, 2, 3].min'
ruby 3.1.0dev (2021-09-20T10:07:58Z master cb8434563d) [x86_64-linux]
:max
:min
Actions #1

Updated by wanabe (_ wanabe) about 1 month ago

  • ruby -v set to ruby 3.1.0dev (2021-09-20T10:07:58Z master cb8434563d) [x86_64-linux]

Updated by jeremyevans0 (Jeremy Evans) 26 days ago

I submitted a pull request to fix this issue: https://github.com/ruby/ruby/pull/4911

Actions #3

Updated by jeremyevans (Jeremy Evans) 25 days ago

  • Status changed from Open to Closed

Applied in changeset git|1f5f8a187adb746b01cc95c3f29a0a355f513374.


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]

Actions

Also available in: Atom PDF