aboutsummaryrefslogtreecommitdiffstats
path: root/object.c
diff options
context:
space:
mode:
Diffstat (limited to 'object.c')
-rw-r--r--object.c49
1 files changed, 43 insertions, 6 deletions
diff --git a/object.c b/object.c
index 42d9d2509b..cad41e686c 100644
--- a/object.c
+++ b/object.c
@@ -1833,8 +1833,14 @@ rb_mod_const_defined(int argc, VALUE *argv, VALUE mod)
else {
rb_scan_args(argc, argv, "11", &name, &recur);
}
- if (!(id = rb_check_id(name)) && rb_is_const_name(name))
- return Qfalse;
+ if (!(id = rb_check_id(name))) {
+ if (rb_is_const_name(name)) {
+ return Qfalse;
+ }
+ else {
+ rb_name_error_str(name, "wrong constant name %s", RSTRING_PTR(name));
+ }
+ }
if (!rb_is_const_id(id)) {
rb_name_error(id, "wrong constant name %s", rb_id2name(id));
}
@@ -1864,8 +1870,16 @@ rb_mod_const_defined(int argc, VALUE *argv, VALUE mod)
static VALUE
rb_obj_ivar_get(VALUE obj, VALUE iv)
{
- ID id = rb_to_id(iv);
+ ID id = rb_check_id(iv);
+ if (!id) {
+ if (rb_is_instance_name(iv)) {
+ return Qnil;
+ }
+ else {
+ rb_name_error_str(iv, "`%s' is not allowed as an instance variable name", RSTRING_PTR(iv));
+ }
+ }
if (!rb_is_instance_id(id)) {
rb_name_error(id, "`%s' is not allowed as an instance variable name", rb_id2name(id));
}
@@ -1926,7 +1940,14 @@ rb_obj_ivar_defined(VALUE obj, VALUE iv)
{
ID id = rb_check_id(iv);
- if (!id && rb_is_instance_name(iv)) return Qfalse;
+ if (!id) {
+ if (rb_is_instance_name(iv)) {
+ return Qfalse;
+ }
+ else {
+ rb_name_error_str(iv, "`%s' is not allowed as an instance variable name", RSTRING_PTR(iv));
+ }
+ }
if (!rb_is_instance_id(id)) {
rb_name_error(id, "`%s' is not allowed as an instance variable name", rb_id2name(id));
}
@@ -1950,8 +1971,17 @@ rb_obj_ivar_defined(VALUE obj, VALUE iv)
static VALUE
rb_mod_cvar_get(VALUE obj, VALUE iv)
{
- ID id = rb_to_id(iv);
+ ID id = rb_check_id(iv);
+ if (!id) {
+ if (rb_is_class_name(iv)) {
+ rb_name_error_str(iv, "uninitialized class variable %s in %s",
+ RSTRING_PTR(iv), rb_class2name(obj));
+ }
+ else {
+ rb_name_error_str(iv, "`%s' is not allowed as a class variable name", RSTRING_PTR(iv));
+ }
+ }
if (!rb_is_class_id(id)) {
rb_name_error(id, "`%s' is not allowed as a class variable name", rb_id2name(id));
}
@@ -2006,7 +2036,14 @@ rb_mod_cvar_defined(VALUE obj, VALUE iv)
{
ID id = rb_check_id(iv);
- if (!id && rb_is_class_name(iv)) return Qfalse;
+ if (!id) {
+ if (rb_is_class_name(iv)) {
+ return Qfalse;
+ }
+ else {
+ rb_name_error_str(iv, "`%s' is not allowed as a class variable name", RSTRING_PTR(iv));
+ }
+ }
if (!rb_is_class_id(id)) {
rb_name_error(id, "`%s' is not allowed as a class variable name", rb_id2name(id));
}