* variable.c (rb_const_set): show the previous definition

location.  [EXPERIMENTAL]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33175 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2011-09-03 15:11:53 +00:00
parent 3e0819c66a
commit bc2a1f2a98
7 changed files with 40 additions and 1 deletions

View file

@ -2057,8 +2057,13 @@ rb_const_set(VALUE klass, ID id, VALUE val)
autoload_delete(klass, id);
}
else {
const char *name = rb_id2name(id);
visibility = ce->flag;
rb_warn("already initialized constant %s", rb_id2name(id));
rb_warn("already initialized constant %s", name);
if (!NIL_P(ce->file) && ce->line) {
rb_compile_warn(RSTRING_PTR(ce->file), ce->line,
"previous definition of %s was here", name);
}
}
}
}
@ -2068,6 +2073,8 @@ rb_const_set(VALUE klass, ID id, VALUE val)
ce = ALLOC(rb_const_entry_t);
ce->flag = (rb_const_flag_t)visibility;
ce->value = val;
ce->file = rb_sourcefilename();
ce->line = rb_sourceline();
st_insert(RCLASS_CONST_TBL(klass), (st_data_t)id, (st_data_t)ce);
}