summaryrefslogtreecommitdiff
path: root/random.c
diff options
context:
space:
mode:
authorKazuhiro NISHIYAMA <zn@mbf.nifty.com>2019-12-15 14:47:36 +0900
committerKazuhiro NISHIYAMA <zn@mbf.nifty.com>2019-12-15 14:47:36 +0900
commite2b192f7d5b4f0e2133bb6cf03cfc609258826be (patch)
treea80b27431d00bc4e097c9d755de6ea0008552208 /random.c
parentdb2ea9b0c5fb49a04af1b299a37e92f81d7cccd2 (diff)
rand(beginless_range) raise Errno::EDOM instead of TypeError
same as `rand(endless_range)` Before: ``` $ ruby -e 'rand(..1)' Traceback (most recent call last): 2: from -e:1:in `<main>' 1: from -e:1:in `rand' -e:1:in `-': nil can't be coerced into Integer (TypeError) ``` After: ``` $ ruby -e 'rand(..1)' Traceback (most recent call last): 1: from -e:1:in `<main>' -e:1:in `rand': Numerical argument out of domain (Errno::EDOM) ```
Diffstat (limited to 'random.c')
-rw-r--r--random.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/random.c b/random.c
index f72abb0a6c..68b47bcf1b 100644
--- a/random.c
+++ b/random.c
@@ -1043,9 +1043,11 @@ random_s_bytes(VALUE obj, VALUE len)
static VALUE
range_values(VALUE vmax, VALUE *begp, VALUE *endp, int *exclp)
{
- VALUE end;
+ VALUE beg, end;
- if (!rb_range_values(vmax, begp, &end, exclp)) return Qfalse;
+ if (!rb_range_values(vmax, &beg, &end, exclp)) return Qfalse;
+ if (begp) *begp = beg;
+ if (NIL_P(beg)) return Qnil;
if (endp) *endp = end;
if (NIL_P(end)) return Qnil;
return rb_check_funcall_default(end, id_minus, 1, begp, Qfalse);