summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/numeric.c b/numeric.c
index 86de28eb6c..f61b1349a6 100644
--- a/numeric.c
+++ b/numeric.c
@@ -251,6 +251,12 @@ coerce_rescue(VALUE *x)
return Qnil; /* dummy */
}
+static VALUE
+coerce_rescue_quiet(VALUE *x)
+{
+ return Qundef;
+}
+
static int
do_coerce(VALUE *x, VALUE *y, int err)
{
@@ -266,10 +272,18 @@ do_coerce(VALUE *x, VALUE *y, int err)
return FALSE;
}
- ary = rb_rescue(coerce_body, (VALUE)a, err ? coerce_rescue : 0, (VALUE)a);
+ ary = rb_rescue(coerce_body, (VALUE)a, err ? coerce_rescue : coerce_rescue_quiet, (VALUE)a);
+ if (ary == Qundef) {
+ rb_warn("Numerical comparison operators will no more rescue exceptions of #coerce");
+ rb_warn("in the next release. Return nil in #coerce if the coercion is impossible.");
+ return FALSE;
+ }
if (!RB_TYPE_P(ary, T_ARRAY) || RARRAY_LEN(ary) != 2) {
if (err) {
rb_raise(rb_eTypeError, "coerce must return [x, y]");
+ } else if (!NIL_P(ary)) {
+ rb_warn("Bad return value for #coerce, called by numerical comparison operators.");
+ rb_warn("#coerce must return [x, y]. The next release will raise an error for this.");
}
return FALSE;
}