Commit 0692f791 authored by KOBAYASHI Shuji's avatar KOBAYASHI Shuji

Simplify conversion process for `i` in `mrb_get_args()`

parent 8c8e6e25
......@@ -838,29 +838,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
p = va_arg(ap, mrb_int*);
if (i < argc) {
switch (mrb_type(ARGV[arg_i])) {
case MRB_TT_FIXNUM:
*p = mrb_fixnum(ARGV[arg_i]);
break;
#ifndef MRB_WITHOUT_FLOAT
case MRB_TT_FLOAT:
{
mrb_float f = mrb_float(ARGV[arg_i]);
if (!FIXABLE_FLOAT(f)) {
mrb_raise(mrb, E_RANGE_ERROR, "float too big for int");
}
*p = (mrb_int)f;
}
break;
#endif
case MRB_TT_STRING:
mrb_raise(mrb, E_TYPE_ERROR, "no implicit conversion of String into Integer");
break;
default:
*p = mrb_fixnum(mrb_Integer(mrb, ARGV[arg_i]));
break;
}
*p = mrb_fixnum(mrb_to_int(mrb, ARGV[arg_i]));
arg_i++;
i++;
}
......
......@@ -37,11 +37,14 @@ end
assert('String#*', '15.2.10.5.5') do
assert_equal 'aaaaa', 'a' * 5
assert_equal '', 'a' * 0
assert_raise(ArgumentError) do
'a' * -1
end
assert_equal 'aa', 'a' * 2.1
assert_raise(ArgumentError) { 'a' * -1 }
assert_raise(RangeError) { '' * 1e30 }
assert_raise(RangeError) { '' * Float::INFINITY }
assert_raise(RangeError) { '' * Float::NAN }
assert_raise(TypeError) { 'a' * '1' }
assert_raise(TypeError) { 'a' * nil }
end
assert('String#[]', '15.2.10.5.6') do
# length of args is 1
a = 'abc'[0]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment