Don't call + and < in Integer.times for !FIXNUM
The methods aren't called for FIXNUM, and it's best to have consistent behavior. Fixes [Bug #18377]
This commit is contained in:
parent
e387458da9
commit
fe1725236c
Notes:
git
2021-12-02 09:22:12 +09:00
@ -5697,9 +5697,9 @@ int_dotimes(VALUE num)
|
|||||||
VALUE i = INT2FIX(0);
|
VALUE i = INT2FIX(0);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (!RTEST(rb_funcall(i, '<', 1, num))) break;
|
if (!RTEST(int_le(i, num))) break;
|
||||||
rb_yield(i);
|
rb_yield(i);
|
||||||
i = rb_funcall(i, '+', 1, INT2FIX(1));
|
i = rb_int_plus(i, INT2FIX(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return num;
|
return num;
|
||||||
|
@ -299,6 +299,31 @@ class TestInteger < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_times_bignum_redefine_plus_lt
|
||||||
|
assert_separately([], "#{<<-"begin;"}\n#{<<~"end;"}")
|
||||||
|
begin;
|
||||||
|
called = false
|
||||||
|
Integer.class_eval do
|
||||||
|
alias old_plus +
|
||||||
|
undef +
|
||||||
|
define_method(:+){|x| called = true; 1}
|
||||||
|
alias old_lt <
|
||||||
|
undef <
|
||||||
|
define_method(:<){|x| called = true}
|
||||||
|
end
|
||||||
|
big = 2**65
|
||||||
|
big.times{break 0}
|
||||||
|
Integer.class_eval do
|
||||||
|
undef +
|
||||||
|
alias + old_plus
|
||||||
|
undef <
|
||||||
|
alias < old_lt
|
||||||
|
end
|
||||||
|
bug18377 = "[ruby-core:106361]"
|
||||||
|
assert_equal(false, called, bug18377)
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
|
||||||
def assert_int_equal(expected, result, mesg = nil)
|
def assert_int_equal(expected, result, mesg = nil)
|
||||||
assert_kind_of(Integer, result, mesg)
|
assert_kind_of(Integer, result, mesg)
|
||||||
assert_equal(expected, result, mesg)
|
assert_equal(expected, result, mesg)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user