summaryrefslogtreecommitdiff
path: root/object.c
diff options
context:
space:
mode:
Diffstat (limited to 'object.c')
-rw-r--r--object.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/object.c b/object.c
index 73a24c9417..8e1c25b519 100644
--- a/object.c
+++ b/object.c
@@ -853,8 +853,12 @@ rb_convert_type(val, type, tname, method)
arg1.val = arg2.val = val;
arg1.s = method;
arg2.s = tname;
- val = rb_rescue(to_type, (VALUE)&arg1, fail_to_type, (VALUE)&arg2);
- Check_Type(val, type);
+ val = rb_rescue2(to_type, (VALUE)&arg1, fail_to_type, (VALUE)&arg2,
+ rb_eStandardError, rb_eNameError, 0);
+ if (TYPE(val) != type) {
+ rb_raise(rb_eTypeError, "%s#%s should return %s",
+ rb_class2name(CLASS_OF(arg1.val)), method, tname);
+ }
return val;
}
@@ -888,9 +892,11 @@ rb_Integer(val)
arg1.val = arg2.val = val;
arg1.s = "to_i";
arg2.s = "Integer";
- val = rb_rescue(to_type, (VALUE)&arg1, fail_to_type, (VALUE)&arg2);
+ val = rb_rescue2(to_type, (VALUE)&arg1, fail_to_type, (VALUE)&arg2,
+ rb_eStandardError, rb_eNameError, 0);
if (!rb_obj_is_kind_of(val, rb_cInteger)) {
- rb_raise(rb_eTypeError, "to_i should return Integer");
+ rb_raise(rb_eTypeError, "%s#to_i should return Integer",
+ rb_class2name(CLASS_OF(arg1.val)));
}
return val;
}