vm_method.c: preserve encodings

* vm_method.c (rb_method_entry_make): preserve encodings of
  constant names in warning messages.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48573 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-11-25 18:44:12 +00:00
parent 5d4aad2b1b
commit f2fc80cebe
2 changed files with 13 additions and 9 deletions

View File

@ -49,11 +49,15 @@ class TestConst < Test::Unit::TestCase
def test_redefinition def test_redefinition
c = Class.new c = Class.new
c.const_set(:X, 1) name = "X\u{5b9a 6570}"
assert_output(nil, <<-WARNING) {c.const_set(:X, 2)} c.const_set(name, 1)
#{__FILE__}:#{__LINE__-1}: warning: already initialized constant #{c}::X prev_line = __LINE__ - 1
#{__FILE__}:#{__LINE__-3}: warning: previous definition of X was here EnvUtil.with_default_internal(Encoding::UTF_8) do
assert_output(nil, <<-WARNING) {c.const_set(name, 2)}
#{__FILE__}:#{__LINE__-1}: warning: already initialized constant #{c}::#{name}
#{__FILE__}:#{prev_line}: warning: previous definition of #{name} was here
WARNING WARNING
end
code = <<-PRE code = <<-PRE
olderr = $stderr.dup olderr = $stderr.dup
$stderr.reopen(File::NULL, "wb") $stderr.reopen(File::NULL, "wb")

View File

@ -322,7 +322,7 @@ rb_method_entry_make(VALUE klass, ID mid, rb_method_type_t type,
old_def->type != VM_METHOD_TYPE_ZSUPER) { old_def->type != VM_METHOD_TYPE_ZSUPER) {
rb_iseq_t *iseq = 0; rb_iseq_t *iseq = 0;
rb_warning("method redefined; discarding old %s", rb_id2name(mid)); rb_warning("method redefined; discarding old %"PRIsVALUE, rb_id2str(mid));
switch (old_def->type) { switch (old_def->type) {
case VM_METHOD_TYPE_ISEQ: case VM_METHOD_TYPE_ISEQ:
iseq = old_def->body.iseq; iseq = old_def->body.iseq;
@ -336,8 +336,8 @@ rb_method_entry_make(VALUE klass, ID mid, rb_method_type_t type,
if (iseq && !NIL_P(iseq->location.path)) { if (iseq && !NIL_P(iseq->location.path)) {
int line = iseq->line_info_table ? FIX2INT(rb_iseq_first_lineno(iseq->self)) : 0; int line = iseq->line_info_table ? FIX2INT(rb_iseq_first_lineno(iseq->self)) : 0;
rb_compile_warning(RSTRING_PTR(iseq->location.path), line, rb_compile_warning(RSTRING_PTR(iseq->location.path), line,
"previous definition of %s was here", "previous definition of %"PRIsVALUE" was here",
rb_id2name(old_def->original_id)); rb_id2str(old_def->original_id));
} }
} }
@ -762,8 +762,8 @@ remove_method(VALUE klass, ID mid)
if (!st_lookup(RCLASS_M_TBL(klass), mid, &data) || if (!st_lookup(RCLASS_M_TBL(klass), mid, &data) ||
!(me = (rb_method_entry_t *)data) || !(me = (rb_method_entry_t *)data) ||
(!me->def || me->def->type == VM_METHOD_TYPE_UNDEF)) { (!me->def || me->def->type == VM_METHOD_TYPE_UNDEF)) {
rb_name_error(mid, "method `%s' not defined in %s", rb_name_error(mid, "method `%"PRIsVALUE"' not defined in %"PRIsVALUE,
rb_id2name(mid), rb_class2name(klass)); rb_id2str(mid), rb_class_path(klass));
} }
key = (st_data_t)mid; key = (st_data_t)mid;
st_delete(RCLASS_M_TBL(klass), &key, &data); st_delete(RCLASS_M_TBL(klass), &key, &data);