Skip to content

Commit

Permalink
[DO NOT MERGE] Add 2.7 Range#minmax monkeypatch
Browse files Browse the repository at this point in the history
Unfortunately, the 2.7 implementation actually contains a bug which
causes the underlying C implementation of Range#max to delegate to
Enumerable#minmax instead of Enumerable#max, since the optimized
Range#minmax C implementation skips the Ruby call to Range#max, and
calls straight into the C function range_max, thereby failing to change
the execution context, and causing the incorrect super call.

Pending a fix in MRI, Range#minmax is monkeypatched with an equivalent
fix, allowing the specs to be worked on. Once the fix is merged
upstream, this commit can be reverted to remove the monkeypatch, and the
specs should continue to pass.
  • Loading branch information
sambostock committed Jul 4, 2020
1 parent 42ef8e4 commit 3fd6910
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/range/minmax_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
@y.should_receive(:<=>).with(@y).any_number_of_times.and_return(0)
end

ruby_version_is '2.7' do # TODO: Remove this before merging!
class Range
# This monkey patch roughly matches the implementation of the bug fix in MRI's range.c
def minmax
return super if block_given?

[min, max]
end
end
end

describe 'by enumerating the range' do
before(:each) do
@x.should_receive(:succ).once.and_return(@y)
Expand Down

0 comments on commit 3fd6910

Please sign in to comment.