summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--proc.c8
-rw-r--r--test/ruby/test_class.rb4
-rw-r--r--test/ruby/test_module.rb4
-rw-r--r--vm_method.c19
5 files changed, 37 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index b1014c037..2ee8ae5ba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/proc.c b/proc.c
index 1b5e5bc63..5ed3c0184 100644
--- a/proc.c
+++ b/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);
diff --git a/test/ruby/test_class.rb b/test/ruby/test_class.rb
index 093448f2c..409fc49e4 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 bfb347c46..c50cd38b7 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 808c64c47..a879d0567 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);
}