Warn redefinitions of some methods on Object

[Bug #5473] [Bug #14670] [Bug #15382]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66262 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-12-06 23:06:13 +00:00
parent 973f84ef55
commit 76e3af82d5
4 changed files with 11 additions and 3 deletions

View File

@ -1344,6 +1344,7 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status|
def test_super_in_method_missing
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
begin;
$VERBOSE = nil
class Object
def method_missing(name, *args, &block)
super

View File

@ -188,7 +188,7 @@ class TestInteger < Test::Unit::TestCase
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
begin;
def method_missing(*);"";end
class Integer;def method_missing(*);"";end;end
assert_equal(0, Integer("0", 2))
end;
end

View File

@ -883,6 +883,7 @@ class TestObject < Test::Unit::TestCase
['ArgumentError.new("bug5473")', 'ArgumentError, "bug5473"', '"bug5473"'].each do |code|
exc = code[/\A[A-Z]\w+/] || 'RuntimeError'
assert_separately([], <<-SRC)
$VERBOSE = nil
class ::Object
def method_missing(m, *a, &b)
raise #{code}

View File

@ -605,8 +605,14 @@ rb_method_entry_make(VALUE klass, ID mid, VALUE defined_class, rb_method_visibil
rb_clear_method_cache_by_class(klass);
/* check mid */
if (klass == rb_cObject && mid == idInitialize) {
rb_warn("redefining Object#initialize may cause infinite loop");
if (klass == rb_cObject) {
switch (mid) {
case idInitialize:
case idRespond_to_missing:
case idMethodMissing:
case idRespond_to:
rb_warn("redefining Object#%s may cause infinite loop", rb_id2name(mid));
}
}
/* check mid */
if (mid == object_id || mid == id__send__) {