diff options
author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-09-02 22:39:22 +0000 |
---|---|---|
committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-09-02 22:39:22 +0000 |
commit | 4993cf9e24769ad69a6b0c7d26324f3af88b2ef3 (patch) | |
tree | c475db76ea3131b463fb7ae656755f22a4379c61 | |
parent | 3065dd71e83565a1c21881aa5cd684d7cca16f96 (diff) |
Numeral#step should raise TypeError if a non-numeric parameter is given.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42785 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | numeric.c | 18 |
2 files changed, 21 insertions, 2 deletions
@@ -1,3 +1,8 @@ +Tue Sep 3 07:31:29 2013 Akinori MUSHA <[email protected]> + + * numeric.c (NUM_STEP_SCAN_ARGS): Numeral#step should raise + TypeError if a non-numeric parameter is given. + Tue Sep 3 07:28:49 2013 Tanaka Akira <[email protected]> * internal.h (bit_length): Add casts to fix complation error with @@ -1858,9 +1858,23 @@ ruby_num_interval_step_size(VALUE from, VALUE to, VALUE step, int excl) rb_raise(rb_eArgError, "step can't be 0"); \ } \ } \ - if (NIL_P(step)) step = INT2FIX(1); \ + if (NIL_P(step)) { \ + step = INT2FIX(1); \ + } \ + else { \ + if (!rb_obj_is_kind_of(step, rb_cNumeric)) { \ + rb_raise(rb_eTypeError, "step must be numeric"); \ + } \ + } \ desc = negative_int_p(step); \ - if (NIL_P(to)) to = desc ? DBL2NUM(-INFINITY) : DBL2NUM(INFINITY); \ + if (NIL_P(to)) { \ + to = desc ? DBL2NUM(-INFINITY) : DBL2NUM(INFINITY); \ + } \ + else { \ + if (!rb_obj_is_kind_of(to, rb_cNumeric)) { \ + rb_raise(rb_eTypeError, "limit must be numeric"); \ + } \ + } \ if (TYPE(to) == T_FLOAT) { \ double f = RFLOAT_VALUE(to); \ inf = isinf(f) && (signbit(f) ? desc : !desc); \ |