Emit warning for other method redefinition types
This commit ensures warnings about `object_id` and `__send__` method redefinitions are emitted for other method types such as aliases, procs, and attr readers—anything except C functions.
This commit is contained in:
parent
a985695b9e
commit
5792bd7149
@ -480,16 +480,31 @@ class TestObject < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_redefine_method_which_may_case_serious_problem
|
def test_redefine_method_which_may_case_serious_problem
|
||||||
assert_in_out_err([], <<-INPUT, [], %r"warning: redefining 'object_id' may cause serious problems$")
|
%w(object_id __send__).each do |m|
|
||||||
|
assert_in_out_err([], <<-INPUT, [], %r"warning: redefining '#{m}' may cause serious problems$")
|
||||||
$VERBOSE = false
|
$VERBOSE = false
|
||||||
def (Object.new).object_id; end
|
def (Object.new).#{m}; end
|
||||||
INPUT
|
INPUT
|
||||||
|
|
||||||
assert_in_out_err([], <<-INPUT, [], %r"warning: redefining '__send__' may cause serious problems$")
|
assert_in_out_err([], <<-INPUT, [], %r"warning: redefining '#{m}' may cause serious problems$")
|
||||||
$VERBOSE = false
|
$VERBOSE = false
|
||||||
def (Object.new).__send__; end
|
Class.new.define_method(:#{m}) {}
|
||||||
INPUT
|
INPUT
|
||||||
|
|
||||||
|
assert_in_out_err([], <<-INPUT, [], %r"warning: redefining '#{m}' may cause serious problems$")
|
||||||
|
$VERBOSE = false
|
||||||
|
Class.new.attr_reader(:#{m})
|
||||||
|
INPUT
|
||||||
|
|
||||||
|
assert_in_out_err([], <<-INPUT, [], %r"warning: redefining '#{m}' may cause serious problems$")
|
||||||
|
$VERBOSE = false
|
||||||
|
Class.new do
|
||||||
|
def foo; end
|
||||||
|
alias #{m} foo
|
||||||
|
end
|
||||||
|
INPUT
|
||||||
|
end
|
||||||
|
|
||||||
bug10421 = '[ruby-dev:48691] [Bug #10421]'
|
bug10421 = '[ruby-dev:48691] [Bug #10421]'
|
||||||
assert_in_out_err([], <<-INPUT, ["1"], [], bug10421)
|
assert_in_out_err([], <<-INPUT, ["1"], [], bug10421)
|
||||||
$VERBOSE = false
|
$VERBOSE = false
|
||||||
|
@ -1062,7 +1062,7 @@ rb_method_entry_make(VALUE klass, ID mid, VALUE defined_class, rb_method_visibil
|
|||||||
}
|
}
|
||||||
/* check mid */
|
/* check mid */
|
||||||
if (mid == object_id || mid == id__send__) {
|
if (mid == object_id || mid == id__send__) {
|
||||||
if (type == VM_METHOD_TYPE_ISEQ && search_method(klass, mid, 0)) {
|
if (type != VM_METHOD_TYPE_CFUNC && search_method(klass, mid, 0)) {
|
||||||
rb_warn("redefining '%s' may cause serious problems", rb_id2name(mid));
|
rb_warn("redefining '%s' may cause serious problems", rb_id2name(mid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user