зеркало из https://github.com/github/ruby.git
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:
Родитель
31457774a8
Коммит
b996367eb5
26
variable.c
26
variable.c
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче