diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2018-09-20 10:13:36 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2018-09-20 10:13:36 +0900 |
| commit | 8e91316bd64aa39b3afeffb0ade5eb38b05d3953 (patch) | |
| tree | fabce96f895417c6d2252860211aeb7b4df97a31 /mrbgems/mruby-random | |
| parent | 3820ef791f3ccb766956d12534ae519f4923ac7e (diff) | |
| parent | cb85fa6787ea9467f81be41570a36b475b7ef061 (diff) | |
| download | mruby-8e91316bd64aa39b3afeffb0ade5eb38b05d3953.tar.gz mruby-8e91316bd64aa39b3afeffb0ade5eb38b05d3953.zip | |
Merge branch 'no-implicit-conversion' into mruby2-draftmruby2-draft
Diffstat (limited to 'mrbgems/mruby-random')
| -rw-r--r-- | mrbgems/mruby-random/src/random.c | 12 | ||||
| -rw-r--r-- | mrbgems/mruby-random/test/random.rb | 12 |
2 files changed, 6 insertions, 18 deletions
diff --git a/mrbgems/mruby-random/src/random.c b/mrbgems/mruby-random/src/random.c index 5b926a228..68209840a 100644 --- a/mrbgems/mruby-random/src/random.c +++ b/mrbgems/mruby-random/src/random.c @@ -79,12 +79,12 @@ get_opt(mrb_state* mrb) mrb_get_args(mrb, "|o", &arg); if (!mrb_nil_p(arg)) { - arg = mrb_check_convert_type(mrb, arg, MRB_TT_FIXNUM, "Fixnum", "to_int"); - if (mrb_nil_p(arg)) { - mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument type"); - } - if (mrb_fixnum(arg) < 0) { - arg = mrb_fixnum_value(0 - mrb_fixnum(arg)); + mrb_int i; + + arg = mrb_to_int(mrb, arg); + i = mrb_fixnum(arg); + if (i < 0) { + arg = mrb_fixnum_value(0 - i); } } return arg; diff --git a/mrbgems/mruby-random/test/random.rb b/mrbgems/mruby-random/test/random.rb index 1c59be3a6..1653ae4a6 100644 --- a/mrbgems/mruby-random/test/random.rb +++ b/mrbgems/mruby-random/test/random.rb @@ -74,15 +74,3 @@ assert('Array#shuffle!(random)') do ary1 != [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and 10.times { |x| ary1.include? x } and ary1 == ary2 end - -assert('Array#sample checks input length after reading arguments') do - $ary = [1, 2, 3] - class ArrayChange - def to_i - $ary << 4 - 4 - end - end - - assert_equal [1, 2, 3, 4], $ary.sample(ArrayChange.new).sort -end |
