* vm_method.c (rb_add_method_def): show the location where

overwritten method was defined.  [ruby-dev:39400]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25169 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2009-09-30 04:15:46 +00:00
Родитель 331fdbe822
Коммит a71d47a380
5 изменённых файлов: 37 добавлений и 3 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Wed Sep 30 13:15:45 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* vm_method.c (rb_add_method_def): show the location where
overwritten method was defined. [ruby-dev:39400]
Wed Sep 30 00:37:27 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* enumerator.c (enumerator_block_call): extracted.

8
proc.c
Просмотреть файл

@ -648,8 +648,10 @@ rb_proc_arity(VALUE self)
return -1;
}
static rb_iseq_t *
get_proc_iseq(VALUE self, int *is_proc)
#define get_proc_iseq rb_proc_get_iseq
rb_iseq_t *
rb_proc_get_iseq(VALUE self, int *is_proc)
{
rb_proc_t *proc;
rb_iseq_t *iseq;
@ -894,7 +896,7 @@ mnew(VALUE klass, VALUE obj, ID id, VALUE mclass, int scope)
rb_method_definition_t *def = 0;
again:
me = rb_method_entry(klass, id);
me = rb_method_entry(klass, id);
if (UNDEFINED_METHOD_ENTRY_P(me)) {
ID rmiss = rb_intern("respond_to_missing?");
VALUE sym = ID2SYM(id);

Просмотреть файл

@ -106,6 +106,8 @@ class TestClass < Test::Unit::TestCase
end
def test_method_redefinition
feature2155 = '[ruby-dev:39400]'
line = __LINE__+4
stderr = EnvUtil.verbose_warning do
Class.new do
@ -114,6 +116,7 @@ class TestClass < Test::Unit::TestCase
end
end
assert_match(/:#{line}: warning: method redefined; discarding old foo/, stderr)
assert_match(/:#{line-1}: warning: previous definition of foo/, stderr, feature2155)
stderr = EnvUtil.verbose_warning do
Class.new do
@ -141,6 +144,7 @@ class TestClass < Test::Unit::TestCase
end
end
assert_match(/:#{line}: warning: method redefined; discarding old foo/, stderr)
assert_match(/:#{line-1}: warning: previous definition of foo/, stderr, feature2155)
stderr = EnvUtil.verbose_warning do
Class.new do

Просмотреть файл

@ -788,6 +788,8 @@ class TestModule < Test::Unit::TestCase
end
def test_method_redefinition
feature2155 = '[ruby-dev:39400]'
line = __LINE__+4
stderr = EnvUtil.verbose_warning do
Module.new do
@ -796,6 +798,7 @@ class TestModule < Test::Unit::TestCase
end
end
assert_match(/:#{line}: warning: method redefined; discarding old foo/, stderr)
assert_match(/:#{line-1}: warning: previous definition of foo/, stderr, feature2155)
stderr = EnvUtil.verbose_warning do
Module.new do
@ -823,6 +826,7 @@ class TestModule < Test::Unit::TestCase
end
end
assert_match(/:#{line}: warning: method redefined; discarding old foo/, stderr)
assert_match(/:#{line-1}: warning: previous definition of foo/, stderr, feature2155)
stderr = EnvUtil.verbose_warning do
Module.new do

Просмотреть файл

@ -188,7 +188,26 @@ rb_add_method_def(VALUE klass, ID mid, rb_method_type_t type, rb_method_definiti
old_def->alias_count == 0 &&
old_def->type != VM_METHOD_TYPE_UNDEF &&
old_def->type != VM_METHOD_TYPE_ZSUPER) {
extern rb_iseq_t *rb_proc_get_iseq(VALUE proc, int *is_proc);
rb_iseq_t *iseq = 0;
rb_warning("method redefined; discarding old %s", rb_id2name(mid));
switch (old_def->type) {
case VM_METHOD_TYPE_ISEQ:
iseq = old_def->body.iseq;
break;
case VM_METHOD_TYPE_BMETHOD:
iseq = rb_proc_get_iseq(old_def->body.proc, 0);
break;
default:
break;
}
if (iseq && !NIL_P(iseq->filename)) {
int line = iseq->insn_info_table ? rb_iseq_first_lineno(iseq) : 0;
rb_compile_warning(RSTRING_PTR(iseq->filename), line,
"previous definition of %s was here",
rb_id2name(old_def->original_id));
}
}
rb_free_method_entry(old_me);
}