diff --git a/ChangeLog b/ChangeLog index 7b4ad08f09..142703a14d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Fri Oct 23 21:10:37 2015 Nobuyoshi Nakada + + * error.c (name_err_mesg_to_str): separate class names from the + receiver description. + + * vm_eval.c (make_no_method_exception, raise_method_missing): add + format specifiers for class names. + Fri Oct 23 18:10:32 2015 SHIBATA Hiroshi * .gitignore: ignored environmantal wrapper files. diff --git a/error.c b/error.c index ce641a0c0d..be9f334296 100644 --- a/error.c +++ b/error.c @@ -1219,20 +1219,19 @@ name_err_mesg_to_str(VALUE obj) mesg = ptr[NAME_ERR_MESG__MESG]; if (NIL_P(mesg)) return Qnil; else { - const char *desc = 0; - VALUE d = 0, args[NAME_ERR_MESG_COUNT]; - int state = 0; + VALUE c, s, d = 0, args[4]; + int state = 0, singleton = 0; obj = ptr[NAME_ERR_MESG__RECV]; switch (obj) { case Qnil: - desc = "nil"; + d = rb_fstring_cstr("nil"); break; case Qtrue: - desc = "true"; + d = rb_fstring_cstr("true"); break; case Qfalse: - desc = "false"; + d = rb_fstring_cstr("false"); break; default: d = rb_protect(rb_inspect, obj, &state); @@ -1241,18 +1240,22 @@ name_err_mesg_to_str(VALUE obj) if (NIL_P(d) || RSTRING_LEN(d) > 65) { d = rb_any_to_s(obj); } - desc = RSTRING_PTR(d); + singleton = (RSTRING_LEN(d) > 0 && RSTRING_PTR(d)[0] == '#'); + d = QUOTE(d); break; } - if (desc && desc[0] != '#') { - d = d ? rb_str_dup(d) : rb_str_new2(desc); - rb_str_cat2(d, ":"); - rb_str_append(d, rb_class_name(CLASS_OF(obj))); + if (!singleton) { + s = rb_fstring_cstr(":"); + c = rb_class_name(CLASS_OF(obj)); } - args[0] = mesg; - args[1] = ptr[NAME_ERR_MESG__NAME]; - args[2] = d; - mesg = rb_f_sprintf(NAME_ERR_MESG_COUNT, args); + else { + c = s = rb_fstring_cstr(""); + } + args[0] = ptr[NAME_ERR_MESG__NAME]; + args[1] = d; + args[2] = s; + args[3] = c; + mesg = rb_str_format(4, args, mesg); } return mesg; } diff --git a/vm_eval.c b/vm_eval.c index 121e2f15bd..ed8bf42496 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -677,7 +677,7 @@ make_no_method_exception(VALUE exc, const char *format, VALUE obj, int argc, con VALUE args[3]; if (!format) { - format = "undefined method `%s' for %s"; + format = "undefined method `%s' for %s%s%s"; } args[n++] = rb_name_err_mesg_new(rb_str_new_cstr(format), obj, argv[0]); args[n++] = argv[0]; @@ -706,17 +706,17 @@ raise_method_missing(rb_thread_t *th, int argc, const VALUE *argv, VALUE obj, stack_check(); if (last_call_status & MISSING_PRIVATE) { - format = "private method `%s' called for %s"; + format = "private method `%s' called for %s%s%s"; } else if (last_call_status & MISSING_PROTECTED) { - format = "protected method `%s' called for %s"; + format = "protected method `%s' called for %s%s%s"; } else if (last_call_status & MISSING_VCALL) { - format = "undefined local variable or method `%s' for %s"; + format = "undefined local variable or method `%s' for %s%s%s"; exc = rb_eNameError; } else if (last_call_status & MISSING_SUPER) { - format = "super: no superclass method `%s' for %s"; + format = "super: no superclass method `%s' for %s%s%s"; } {