diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-07-26 16:05:35 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-07-26 16:05:35 +0000 |
commit | 8603c5934a4e613cdb07b04a1ce86fb1f21fdbd5 (patch) | |
tree | 44fdf5f0b148df430c6c0d667ef8139e73ed9b50 /object.c | |
parent | 298349d03bcdb6c25420d9a92265816d59892a1f (diff) | |
download | ruby-8603c5934a4e613cdb07b04a1ce86fb1f21fdbd5.tar.gz |
* eval_error.c (rb_print_undef_str): new function to raise
NameError for undefined method.
* load.c (rb_mod_autoload_p), object.c (rb_mod_const_get),
variable.c (rb_f_untrace_var, set_const_visibility), vm_method.c
(rb_mod_{remove,undef,alias}_method, set_method_visibility):
remove inadvertent symbol creation. based on the first patch by
Jeremy Evans at [ruby-core:38447]. [Feature #5089]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32686 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'object.c')
-rw-r--r-- | object.c | 20 |
1 files changed, 19 insertions, 1 deletions
@@ -35,6 +35,7 @@ VALUE rb_cFalseClass; static ID id_eq, id_eql, id_match, id_inspect; static ID id_init_copy, id_init_clone, id_init_dup; +static ID id_const_missing; /* * call-seq: @@ -1774,7 +1775,23 @@ rb_mod_const_get(int argc, VALUE *argv, VALUE mod) else { rb_scan_args(argc, argv, "11", &name, &recur); } - id = rb_to_id(name); + id = rb_check_id(&name); + if (!id) { + if (!rb_is_const_name(name)) { + rb_name_error_str(name, "wrong constant name %s", RSTRING_PTR(name)); + } + else if (!rb_method_basic_definition_p(CLASS_OF(mod), id_const_missing)) { + id = rb_to_id(name); + } + else if (mod && rb_class_real(mod) != rb_cObject) { + rb_name_error_str(name, "uninitialized constant %s::%s", + rb_class2name(mod), + RSTRING_PTR(name)); + } + else { + rb_name_error_str(name, "uninitialized constant %s", RSTRING_PTR(name)); + } + } if (!rb_is_const_id(id)) { rb_name_error(id, "wrong constant name %s", rb_id2name(id)); } @@ -2813,6 +2830,7 @@ Init_Object(void) id_init_copy = rb_intern("initialize_copy"); id_init_clone = rb_intern("initialize_clone"); id_init_dup = rb_intern("initialize_dup"); + id_const_missing = rb_intern("const_missing"); for (i=0; conv_method_names[i].method; i++) { conv_method_names[i].id = rb_intern(conv_method_names[i].method); |