ruby-changes:54043
From: nobu <ko1@a...>
Date: Fri, 7 Dec 2018 08:06:19 +0900 (JST)
Subject: [ruby-changes:54043] nobu:r66262 (trunk): Warn redefinitions of some methods on Object
nobu 2018-12-07 08:06:13 +0900 (Fri, 07 Dec 2018) New Revision: 66262 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66262 Log: Warn redefinitions of some methods on Object [Bug #5473] [Bug #14670] [Bug #15382] Modified files: trunk/test/ruby/test_exception.rb trunk/test/ruby/test_integer.rb trunk/test/ruby/test_object.rb trunk/vm_method.c Index: test/ruby/test_integer.rb =================================================================== --- test/ruby/test_integer.rb (revision 66261) +++ test/ruby/test_integer.rb (revision 66262) @@ -188,7 +188,7 @@ class TestInteger < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_integer.rb#L188 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 Index: test/ruby/test_exception.rb =================================================================== --- test/ruby/test_exception.rb (revision 66261) +++ test/ruby/test_exception.rb (revision 66262) @@ -1344,6 +1344,7 @@ $stderr = $stdout; raise "\x82\xa0"') do https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L1344 def test_super_in_method_missing assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}") begin; + $VERBOSE = nil class Object def method_missing(name, *args, &block) super Index: test/ruby/test_object.rb =================================================================== --- test/ruby/test_object.rb (revision 66261) +++ test/ruby/test_object.rb (revision 66262) @@ -883,6 +883,7 @@ class TestObject < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_object.rb#L883 ['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} Index: vm_method.c =================================================================== --- vm_method.c (revision 66261) +++ vm_method.c (revision 66262) @@ -605,8 +605,14 @@ rb_method_entry_make(VALUE klass, ID mid https://github.com/ruby/ruby/blob/trunk/vm_method.c#L605 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__) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/