From bc2a1f2a98b04f040ea485cedd3283f2f3906e4c Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 3 Sep 2011 15:11:53 +0000 Subject: * 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 --- variable.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'variable.c') diff --git a/variable.c b/variable.c index 9526b6226f..3909b799c4 100644 --- a/variable.c +++ b/variable.c @@ -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); } -- cgit v1.2.3