Commit d7a34b62 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #1611 from h2so5/inspect-type

fix TypeError message
parents c514b369 38a0a604
......@@ -292,6 +292,17 @@ mrb_init_object(mrb_state *mrb)
mrb_define_method(mrb, f, "inspect", false_to_s, MRB_ARGS_NONE());
}
static mrb_value
inspect_type(mrb_state *mrb, mrb_value val)
{
if (mrb_type(val) == MRB_TT_FALSE || mrb_type(val) == MRB_TT_TRUE) {
return mrb_inspect(mrb, val);
}
else {
return mrb_str_new_cstr(mrb, mrb_obj_classname(mrb, val));
}
}
static mrb_value
convert_type(mrb_state *mrb, mrb_value val, const char *tname, const char *method, int raise)
{
......@@ -300,7 +311,7 @@ convert_type(mrb_state *mrb, mrb_value val, const char *tname, const char *metho
m = mrb_intern_cstr(mrb, method);
if (!mrb_respond_to(mrb, val, m)) {
if (raise) {
mrb_raisef(mrb, E_TYPE_ERROR, "can't convert %S into %S", val, mrb_str_new_cstr(mrb, tname));
mrb_raisef(mrb, E_TYPE_ERROR, "can't convert %S into %S", inspect_type(mrb, val), mrb_str_new_cstr(mrb, tname));
return mrb_nil_value();
}
else {
......@@ -499,8 +510,9 @@ mrb_to_integer(mrb_state *mrb, mrb_value val, const char *method)
if (mrb_fixnum_p(val)) return val;
v = convert_type(mrb, val, "Integer", method, TRUE);
if (!mrb_obj_is_kind_of(mrb, v, mrb->fixnum_class)) {
mrb_value type = inspect_type(mrb, val);
mrb_raisef(mrb, E_TYPE_ERROR, "can't convert %S to Integer (%S#%S gives %S)",
val, val, mrb_str_new_cstr(mrb, method), v);
type, type, mrb_str_new_cstr(mrb, method), inspect_type(mrb, v));
}
return v;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment