summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--test/ruby/test_const.rb3
-rw-r--r--variable.c6
3 files changed, 12 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 31d8d2da3d..a9982567f1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Thu Nov 29 17:45:10 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * variable.c (rb_const_set): show namespace in warning messages.
+ [Feature #7190]
+
Thu Nov 29 17:31:53 2012 NARUSE, Yui <naruse@ruby-lang.org>
* lib/rubygems.rb (Gem.load_yaml): return if Kernel#gem is not defined
diff --git a/test/ruby/test_const.rb b/test/ruby/test_const.rb
index 31adb2a0ce..dab45b7e08 100644
--- a/test/ruby/test_const.rb
+++ b/test/ruby/test_const.rb
@@ -1,3 +1,4 @@
+# -*- coding: us-ascii -*-
require 'test/unit'
class TestConst < Test::Unit::TestCase
@@ -50,7 +51,7 @@ class TestConst < Test::Unit::TestCase
c = Class.new
c.const_set(:X, 1)
assert_output(nil, <<-WARNING) {c.const_set(:X, 2)}
-#{__FILE__}:#{__LINE__-1}: warning: already initialized constant X
+#{__FILE__}:#{__LINE__-1}: warning: already initialized constant #{c}::X
#{__FILE__}:#{__LINE__-3}: warning: previous definition of X was here
WARNING
end
diff --git a/variable.c b/variable.c
index 9a4be56497..601efb955d 100644
--- a/variable.c
+++ b/variable.c
@@ -2136,7 +2136,11 @@ rb_const_set(VALUE klass, ID id, VALUE val)
else {
const char *name = rb_id2name(id);
visibility = ce->flag;
- rb_warn("already initialized constant %s", name);
+ if (klass == rb_cObject)
+ rb_warn("already initialized constant %s", name);
+ else
+ rb_warn("already initialized constant %s::%s",
+ rb_class2name(klass), name);
if (!NIL_P(ce->file) && ce->line) {
rb_compile_warn(RSTRING_PTR(ce->file), ce->line,
"previous definition of %s was here", name);