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

variable.c: hoisted out overtaken cvar warnings

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62756 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-03-15 07:15:26 +00:00
parent 06af2865de
commit 4691daccc1

View file

@ -2856,6 +2856,23 @@ cvar_front_klass(VALUE klass)
return RCLASS_SUPER(klass);
}
static void
cvar_overtaken(VALUE front, VALUE target, ID id)
{
if (front && target != front) {
st_data_t did = (st_data_t)id;
if (RTEST(ruby_verbose)) {
rb_warning("class variable % "PRIsVALUE" of %"PRIsVALUE" is overtaken by %"PRIsVALUE"",
ID2SYM(id), rb_class_name(original_module(front)),
rb_class_name(original_module(target)));
}
if (BUILTIN_TYPE(front) == T_CLASS) {
st_delete(RCLASS_IV_TBL(front), &did, 0);
}
}
}
#define CVAR_FOREACH_ANCESTORS(klass, v, r) \
for (klass = cvar_front_klass(klass); klass; klass = RCLASS_SUPER(klass)) { \
if (cvar_lookup_at(klass, id, (v))) { \
@ -2876,18 +2893,7 @@ rb_cvar_set(VALUE klass, ID id, VALUE val)
tmp = klass;
CVAR_LOOKUP(0, {if (!front) front = klass; target = klass;});
if (target) {
if (front && target != front) {
st_data_t did = id;
if (RTEST(ruby_verbose)) {
rb_warning("class variable %"PRIsVALUE" of %"PRIsVALUE" is overtaken by %"PRIsVALUE"",
QUOTE_ID(id), rb_class_name(original_module(front)),
rb_class_name(original_module(target)));
}
if (BUILTIN_TYPE(front) == T_CLASS) {
st_delete(RCLASS_IV_TBL(front),&did,0);
}
}
cvar_overtaken(front, target, id);
}
else {
target = tmp;
@ -2913,18 +2919,7 @@ rb_cvar_get(VALUE klass, ID id)
rb_name_err_raise("uninitialized class variable %1$s in %2$s",
tmp, ID2SYM(id));
}
if (front && target != front) {
st_data_t did = id;
if (RTEST(ruby_verbose)) {
rb_warning("class variable %"PRIsVALUE" of %"PRIsVALUE" is overtaken by %"PRIsVALUE"",
QUOTE_ID(id), rb_class_name(original_module(front)),
rb_class_name(original_module(target)));
}
if (BUILTIN_TYPE(front) == T_CLASS) {
st_delete(RCLASS_IV_TBL(front),&did,0);
}
}
cvar_overtaken(front, target, id);
return (VALUE)value;
}