diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-07-23 15:05:03 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-07-23 15:05:03 +0000 |
commit | 4dc1a2180946ab793adee5eb235fc4ee8fa4cefe (patch) | |
tree | 7c078ba1c20373d9c36610c6c98de775e9f44a51 /variable.c | |
parent | a7c15b2617620b79ea734faf31dacc8e72ed5ad1 (diff) | |
download | ruby-4dc1a2180946ab793adee5eb235fc4ee8fa4cefe.tar.gz |
* error.c (rb_name_error_str): new function to raise NameError
with the name string but not ID.
* object.c, proc.c, variable.c: more removal of inadvertent symbol
creation. [Feature #5079]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32645 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'variable.c')
-rw-r--r-- | variable.c | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/variable.c b/variable.c index 251fb3bafb..8a34d2e49d 100644 --- a/variable.c +++ b/variable.c @@ -1299,7 +1299,7 @@ VALUE rb_obj_remove_instance_variable(VALUE obj, VALUE name) { VALUE val = Qnil; - const ID id = rb_to_id(name); + const ID id = rb_check_id(name); st_data_t n, v; struct st_table *iv_index_tbl; st_data_t index; @@ -1307,6 +1307,14 @@ rb_obj_remove_instance_variable(VALUE obj, VALUE name) if (!OBJ_UNTRUSTED(obj) && rb_safe_level() >= 4) rb_raise(rb_eSecurityError, "Insecure: can't modify instance variable"); rb_check_frozen(obj); + if (!id) { + if (rb_is_instance_name(name)) { + rb_name_error_str(name, "instance variable %s not defined", RSTRING_PTR(name)); + } + else { + rb_name_error_str(name, "`%s' is not allowed as an instance variable name", RSTRING_PTR(name)); + } + } if (!rb_is_instance_id(id)) { rb_name_error(id, "`%s' is not allowed as an instance variable name", rb_id2name(id)); } @@ -1677,8 +1685,17 @@ rb_public_const_get_at(VALUE klass, ID id) VALUE rb_mod_remove_const(VALUE mod, VALUE name) { - const ID id = rb_to_id(name); + const ID id = rb_check_id(name); + if (!id) { + if (rb_is_const_name(name)) { + rb_name_error_str(name, "constant %s::%s not defined", + rb_class2name(mod), RSTRING_PTR(name)); + } + else { + rb_name_error_str(name, "`%s' is not allowed as a constant name", RSTRING_PTR(name)); + } + } if (!rb_is_const_id(id)) { rb_name_error(id, "`%s' is not allowed as a constant name", rb_id2name(id)); } @@ -2189,9 +2206,18 @@ rb_mod_class_variables(VALUE obj) VALUE rb_mod_remove_cvar(VALUE mod, VALUE name) { - const ID id = rb_to_id(name); + const ID id = rb_check_id(name); st_data_t val, n = id; + if (!id) { + if (rb_is_class_name(name)) { + rb_name_error_str(name, "class variable %s not defined for %s", + RSTRING_PTR(name), rb_class2name(mod)); + } + else { + rb_name_error_str(name, "wrong class variable name %s", RSTRING_PTR(name)); + } + } if (!rb_is_class_id(id)) { rb_name_error(id, "wrong class variable name %s", rb_id2name(id)); } |