Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion numeric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,10 @@ def downto(to) # :nodoc:
end

from = self
while from >= to
until (cmp = from < to)
if cmp.nil?
Primitive.cstmt! %{ rb_cmperr_reason(from, to, "comparator returned nil"); }
end
yield from
from = from.pred
end
Expand Down
4 changes: 4 additions & 0 deletions test/ruby/test_integer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ def test_downto
a = []
assert_equal(y, y.downto(y-2) {|x| a << x })
assert_equal([y, y-1, y-2], a)

a = []
1.downto(Float::NAN) {|x| a << x; break if a.size == 3 }
assert_equal([1, 0, -1], a)
end

def test_times
Expand Down
17 changes: 17 additions & 0 deletions test/ruby/test_zjit_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,23 @@ def test = 42
}
end

def test_integer_downto_comparator_returns_nil
assert_runs 'true', <<~RUBY
class Integer
def <(other)
nil
end
end

begin
1.downto(3.5) {}
false
rescue ArgumentError => error
error.message.include?("comparator returned nil")
end
RUBY
end

def test_enable_through_env
child_env = {'RUBY_YJIT_ENABLE' => nil, 'RUBY_ZJIT_ENABLE' => '1'}
assert_in_out_err([child_env, '-v'], '') do |stdout, stderr|
Expand Down
Loading