1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

variable.c: move warnings to rb_ivar_get

* variable.c (generic_ivar_get, ivar_get): return undef value instead
  of Qnil with warnings, for uninitialized instance variable.
* variable.c (rb_ivar_get): warn for uninitialized instance variable
  here.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40558 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-05-02 08:30:56 +00:00
parent 31457774a8
commit b996367eb5

View file

@ -908,7 +908,7 @@ rb_generic_ivar_table(VALUE obj)
}
static VALUE
generic_ivar_get(VALUE obj, ID id, int warn)
generic_ivar_get(VALUE obj, ID id, VALUE undef)
{
st_data_t tbl, val;
@ -919,10 +919,7 @@ generic_ivar_get(VALUE obj, ID id, int warn)
}
}
}
if (warn) {
rb_warning("instance variable %"PRIsVALUE" not initialized", QUOTE_ID(id));
}
return Qnil;
return undef;
}
static void
@ -1071,7 +1068,7 @@ rb_copy_generic_ivar(VALUE clone, VALUE obj)
}
static VALUE
ivar_get(VALUE obj, ID id, int warn)
rb_ivar_lookup(VALUE obj, ID id, VALUE undef)
{
VALUE val, *ptr;
struct st_table *iv_index_tbl;
@ -1099,25 +1096,28 @@ ivar_get(VALUE obj, ID id, int warn)
default:
generic:
if (FL_TEST(obj, FL_EXIVAR) || rb_special_const_p(obj))
return generic_ivar_get(obj, id, warn);
return generic_ivar_get(obj, id, undef);
break;
}
if (warn) {
rb_warning("instance variable %"PRIsVALUE" not initialized", QUOTE_ID(id));
}
return Qnil;
return undef;
}
VALUE
rb_ivar_get(VALUE obj, ID id)
{
return ivar_get(obj, id, TRUE);
VALUE iv = rb_ivar_lookup(obj, id, Qundef);
if (iv == Qundef) {
rb_warning("instance variable %"PRIsVALUE" not initialized", QUOTE_ID(id));
iv = Qnil;
}
return iv;
}
VALUE
rb_attr_get(VALUE obj, ID id)
{
return ivar_get(obj, id, FALSE);
return rb_ivar_lookup(obj, id, Qnil);
}
VALUE