Skip to content

Commit b061634

Browse files
committed
range.c: covered for linear objects
* range.c (linear_object_p, range_include): test if covered for linear objects. [ruby-core:69052] [Bug #11113] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50421 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 06cb320 commit b061634

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Sun May 3 10:02:12 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
2+
3+
* range.c (linear_object_p, range_include): test if covered for
4+
linear objects. [ruby-core:69052] [Bug #11113]
5+
16
Fri May 1 13:30:24 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
27

38
* dln.c (dln_load): check if a different libruby is loaded by the

range.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,21 @@ discrete_object_p(VALUE obj)
331331
return rb_respond_to(obj, id_succ);
332332
}
333333

334+
static int
335+
linear_object_p(VALUE obj)
336+
{
337+
if (FIXNUM_P(obj) || FLONUM_P(obj)) return TRUE;
338+
if (SPECIAL_CONST_P(obj)) return FALSE;
339+
switch (BUILTIN_TYPE(obj)) {
340+
case T_FLOAT:
341+
case T_BIGNUM:
342+
return TRUE;
343+
}
344+
if (rb_obj_is_kind_of(obj, rb_cNumeric)) return TRUE;
345+
if (rb_obj_is_kind_of(obj, rb_cTime)) return TRUE;
346+
return FALSE;
347+
}
348+
334349
static VALUE
335350
range_step_size(VALUE range, VALUE args, VALUE eobj)
336351
{
@@ -1156,8 +1171,7 @@ range_include(VALUE range, VALUE val)
11561171
VALUE beg = RANGE_BEG(range);
11571172
VALUE end = RANGE_END(range);
11581173
int nv = FIXNUM_P(beg) || FIXNUM_P(end) ||
1159-
rb_obj_is_kind_of(beg, rb_cNumeric) ||
1160-
rb_obj_is_kind_of(end, rb_cNumeric);
1174+
linear_object_p(beg) || linear_object_p(end);
11611175

11621176
if (nv ||
11631177
!NIL_P(rb_check_to_integer(beg, "to_int")) ||

test/ruby/test_range.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,14 @@ def test_eqq
283283
assert_not_operator(0..10, :===, 11)
284284
end
285285

286+
def test_eqq_time
287+
bug11113 = '[ruby-core:69052] [Bug #11113]'
288+
t = Time.now
289+
assert_nothing_raised(TypeError, bug11113) {
290+
assert_operator(t..(t+10), :===, t+5)
291+
}
292+
end
293+
286294
def test_include
287295
assert_include("a".."z", "c")
288296
assert_not_include("a".."z", "5")

0 commit comments

Comments
 (0)