From f77c97a8ca966ba2a0303b838fa7e04ebc311ecb Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 29 Nov 2012 08:45:13 +0000 Subject: [PATCH] variable.c: show namespace * variable.c (rb_const_set): show namespace in warning messages. [Feature #7190] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37990 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ test/ruby/test_const.rb | 3 ++- variable.c | 6 +++++- 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 + + * variable.c (rb_const_set): show namespace in warning messages. + [Feature #7190] + Thu Nov 29 17:31:53 2012 NARUSE, Yui * 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);