Do not include object string representation in NoMethodError message.

This information is not mandatory but causes a lot of problems in the
past due to infinite recursion by redefining `to_str`, `inspect` etc.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2017-12-23 15:15:03 +09:00
parent ca0f32a208
commit 6999e45742
+1 -20
View File
@@ -956,26 +956,7 @@ mrb_obj_remove_instance_variable(mrb_state *mrb, mrb_value self)
void
mrb_method_missing(mrb_state *mrb, mrb_sym name, mrb_value self, mrb_value args)
{
mrb_sym inspect;
mrb_value repr;
inspect = mrb_intern_lit(mrb, "inspect");
if (mrb->c->ci > mrb->c->cibase && mrb->c->ci[-1].mid == inspect) {
/* method missing in inspect; avoid recursion */
repr = mrb_any_to_s(mrb, self);
}
else if (mrb_respond_to(mrb, self, inspect) && mrb->c->ci - mrb->c->cibase < 16) {
repr = mrb_funcall_argv(mrb, self, inspect, 0, 0);
if (mrb_string_p(repr) && RSTRING_LEN(repr) > 64) {
repr = mrb_any_to_s(mrb, self);
}
}
else {
repr = mrb_any_to_s(mrb, self);
}
mrb_no_method_error(mrb, name, args, "undefined method '%S' for %S",
mrb_sym2str(mrb, name), repr);
mrb_no_method_error(mrb, name, args, "undefined method '%S'", mrb_sym2str(mrb, name));
}
/* 15.3.1.3.30 */