summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2019-12-25 13:35:22 +0900
committerYusuke Endoh <mame@ruby-lang.org>2019-12-25 13:36:23 +0900
commit81e377023c490998a3fec245ca2fb2b3c710c2c6 (patch)
tree9b62548604b2a3f1aaa65d8d541b92e684dfe35c /range.c
parentcd6c013b075c9c27437f30efcee9d4dd9e0ee1c5 (diff)
range.c: Range#min with a beginless one now raise an explicit exception
[Bug #16450]
Diffstat (limited to 'range.c')
-rw-r--r--range.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/range.c b/range.c
index fe956197c6..bf14c0c7a7 100644
--- a/range.c
+++ b/range.c
@@ -1136,6 +1136,10 @@ range_last(int argc, VALUE *argv, VALUE range)
static VALUE
range_min(int argc, VALUE *argv, VALUE range)
{
+ if (NIL_P(RANGE_BEG(range))) {
+ rb_raise(rb_eRangeError, "cannot get the minimum of beginless range");
+ }
+
if (rb_block_given_p()) {
if (NIL_P(RANGE_END(range))) {
rb_raise(rb_eRangeError, "cannot get the minimum of endless range with custom comparison method");
@@ -1185,6 +1189,9 @@ range_max(int argc, VALUE *argv, VALUE range)
}
if (rb_block_given_p() || (EXCL(range) && !nm) || argc) {
+ if (NIL_P(RANGE_BEG(range))) {
+ rb_raise(rb_eRangeError, "cannot get the maximum of beginless range with custom comparison method");
+ }
return rb_call_super(argc, argv);
}
else {