diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | proc.c | 8 | ||||
-rw-r--r-- | test/ruby/test_class.rb | 4 | ||||
-rw-r--r-- | test/ruby/test_module.rb | 4 | ||||
-rw-r--r-- | vm_method.c | 19 |
5 files changed, 37 insertions, 3 deletions
@@ -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. @@ -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); diff --git a/test/ruby/test_class.rb b/test/ruby/test_class.rb index 093448f2c0..409fc49e4e 100644 --- a/test/ruby/test_class.rb +++ b/test/ruby/test_class.rb @@ -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 diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index bfb347c468..c50cd38b79 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -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 diff --git a/vm_method.c b/vm_method.c index 808c64c47e..a879d0567f 100644 --- a/vm_method.c +++ b/vm_method.c @@ -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); } |