なかだです。

メソッド再定義で警告を出すときに、上書きされるほうの定義の場所も
出してはどうでしょうか。


Index: proc.c =================================================================== --- proc.c (revision 25152) +++ proc.c (working copy) @@ -649,6 +649,8 @@ rb_proc_arity(VALUE self) } -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; Index: vm_method.c =================================================================== --- vm_method.c (revision 25152) +++ vm_method.c (working copy) @@ -189,5 +189,24 @@ rb_add_method_def(VALUE klass, ID mid, r 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); Index: test/ruby/test_class.rb =================================================================== --- test/ruby/test_class.rb (revision 25152) +++ test/ruby/test_class.rb (working copy) @@ -115,4 +115,5 @@ class TestClass < Test::Unit::TestCase end assert_match(/:#{line}: warning: method redefined; discarding old foo/, stderr) + assert_match(/:#{line-1}: warning: previous definition of foo/, stderr) stderr = EnvUtil.verbose_warning do @@ -142,4 +143,5 @@ class TestClass < Test::Unit::TestCase end assert_match(/:#{line}: warning: method redefined; discarding old foo/, stderr) + assert_match(/:#{line-1}: warning: previous definition of foo/, stderr) stderr = EnvUtil.verbose_warning do Index: test/ruby/test_module.rb =================================================================== --- test/ruby/test_module.rb (revision 25152) +++ test/ruby/test_module.rb (working copy) @@ -797,4 +797,5 @@ class TestModule < Test::Unit::TestCase end assert_match(/:#{line}: warning: method redefined; discarding old foo/, stderr) + assert_match(/:#{line-1}: warning: previous definition of foo/, stderr) stderr = EnvUtil.verbose_warning do @@ -824,4 +825,5 @@ class TestModule < Test::Unit::TestCase end assert_match(/:#{line}: warning: method redefined; discarding old foo/, stderr) + assert_match(/:#{line-1}: warning: previous definition of foo/, stderr) stderr = EnvUtil.verbose_warning do
-- --- 僕の前にBugはない。 --- 僕の後ろにBugはできる。 中田 伸悦