diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-10-28 06:24:12 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-10-28 06:24:12 +0000 |
commit | ab0ed404a5b0fa4783b2010232d53f590ae5067d (patch) | |
tree | 731069832b17cffaafc9fdcdd394f1976c7ec576 /proc.c | |
parent | 1d5160b390f2894482f89826d671a779384264dd (diff) | |
download | ruby-ab0ed404a5b0fa4783b2010232d53f590ae5067d.tar.gz |
NameError#receiver of uninitialized constant
* error.c (name_err_mesg_to_str): quote the name if unprintable.
* object.c (check_setter_id): use rb_check_id to convert names.
* variable.c (uninitialized_constant): use NameError::message to
keep the receiver of uninitialized constant. [Feature #10881]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52321 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'proc.c')
-rw-r--r-- | proc.c | 45 |
1 files changed, 27 insertions, 18 deletions
@@ -405,18 +405,19 @@ static ID check_local_id(VALUE bindval, volatile VALUE *pname) { ID lid = rb_check_id(pname); - VALUE name = *pname, sym = name; + VALUE name = *pname; if (lid) { if (!rb_is_local_id(lid)) { - name = rb_id2str(lid); - wrong: - rb_name_error_str(sym, "wrong local variable name `% "PRIsVALUE"' for %"PRIsVALUE, - name, bindval); + rb_name_err_raise("wrong local variable name `%1$s' for %2$s", + bindval, ID2SYM(lid)); } } else { - if (!rb_is_local_name(sym)) goto wrong; + if (!rb_is_local_name(name)) { + rb_name_err_raise("wrong local variable name `%1$s' for %2$s", + bindval, name); + } return 0; } return lid; @@ -481,9 +482,10 @@ bind_local_variable_get(VALUE bindval, VALUE sym) GetBindingPtr(bindval, bind); if ((ptr = get_local_variable_ptr(bind->env, lid)) == NULL) { + sym = ID2SYM(lid); undefined: - rb_name_error_str(sym, "local variable `%"PRIsVALUE"' not defined for %"PRIsVALUE, - sym, bindval); + rb_name_err_raise("local variable `%1$s' not defined for %2$s", + bindval, sym); } return *ptr; @@ -1495,24 +1497,30 @@ method_owner(VALUE obj) void rb_method_name_error(VALUE klass, VALUE str) { - const char *s0 = " class"; +#define MSG(s) rb_fstring_cstr("undefined method `%1$s' for"s" `%2$s'") VALUE c = klass; + VALUE s; if (FL_TEST(c, FL_SINGLETON)) { VALUE obj = rb_ivar_get(klass, attached); - switch (TYPE(obj)) { + switch (BUILTIN_TYPE(obj)) { case T_MODULE: case T_CLASS: c = obj; - s0 = ""; + s = MSG(""); } + goto normal_class; } else if (RB_TYPE_P(c, T_MODULE)) { - s0 = " module"; + s = MSG(" module"); + } + else { + normal_class: + s = MSG(" class"); } - rb_name_error_str(str, "undefined method `%"PRIsVALUE"' for%s `%"PRIsVALUE"'", - QUOTE(str), s0, rb_class_name(c)); + rb_name_err_raise_str(s, c, str); +#undef MSG } static VALUE @@ -1616,14 +1624,15 @@ rb_obj_singleton_method(VALUE obj, VALUE vid) id = rb_intern_str(vid); return mnew_missing(klass, obj, id, id, rb_cMethod); } - rb_name_error_str(vid, "undefined singleton method `%"PRIsVALUE"' for `%"PRIsVALUE"'", - QUOTE(vid), obj); + undef: + rb_name_err_raise("undefined singleton method `%1$s' for `%2$s'", + obj, vid); } if (NIL_P(klass = rb_singleton_class_get(obj)) || UNDEFINED_METHOD_ENTRY_P(me = rb_method_entry_at(klass, id)) || UNDEFINED_REFINED_METHOD_P(me->def)) { - rb_name_error(id, "undefined singleton method `%"PRIsVALUE"' for `%"PRIsVALUE"'", - QUOTE_ID(id), obj); + vid = ID2SYM(id); + goto undef; } return mnew_from_me(me, klass, obj, id, rb_cMethod, FALSE); } |