ruby-changes:54978
From: nobu <ko1@a...>
Date: Wed, 6 Mar 2019 20:16:39 +0900 (JST)
Subject: [ruby-changes:54978] nobu:r67185 (trunk): proc.c: call respond_to_missing? with a symbol
nobu 2019-03-06 20:16:34 +0900 (Wed, 06 Mar 2019) New Revision: 67185 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=67185 Log: proc.c: call respond_to_missing? with a symbol [ruby-core:91683] [Bug #15640] Modified files: trunk/proc.c trunk/test/ruby/test_method.rb Index: test/ruby/test_method.rb =================================================================== --- test/ruby/test_method.rb (revision 67184) +++ test/ruby/test_method.rb (revision 67185) @@ -494,6 +494,22 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_method.rb#L494 assert_include mmethods, :meth, 'normal methods are public by default' end + def test_respond_to_missing_argument + obj = Struct.new(:mid).new + def obj.respond_to_missing?(id, *) + self.mid = id + true + end + assert_kind_of(Method, obj.method("bug15640")) + assert_kind_of(Symbol, obj.mid) + assert_equal("bug15640", obj.mid.to_s) + + arg = Struct.new(:to_str).new("bug15640_2") + assert_kind_of(Method, obj.method(arg)) + assert_kind_of(Symbol, obj.mid) + assert_equal("bug15640_2", obj.mid.to_s) + end + define_method(:pm0) {||} define_method(:pm1) {|a|} define_method(:pm2) {|a, b|} Index: proc.c =================================================================== --- proc.c (revision 67184) +++ proc.c (revision 67185) @@ -1387,6 +1387,15 @@ mnew_missing(VALUE klass, VALUE obj, ID https://github.com/ruby/ruby/blob/trunk/proc.c#L1387 } static VALUE +mnew_missing_by_name(VALUE klass, VALUE obj, VALUE *name, int scope, VALUE mclass) +{ + VALUE vid = rb_str_intern(*name); + *name = vid; + if (!respond_to_missing_p(klass, obj, vid, scope)) return Qfalse; + return mnew_missing(klass, obj, SYM2ID(vid), mclass); +} + +static VALUE mnew_internal(const rb_method_entry_t *me, VALUE klass, VALUE iclass, VALUE obj, ID id, VALUE mclass, int scope, int error) { @@ -1690,10 +1699,8 @@ obj_method(VALUE obj, VALUE vid, int sco https://github.com/ruby/ruby/blob/trunk/proc.c#L1699 const VALUE mclass = rb_cMethod; if (!id) { - if (respond_to_missing_p(klass, obj, vid, scope)) { - id = rb_intern_str(vid); - return mnew_missing(klass, obj, id, mclass); - } + VALUE m = mnew_missing_by_name(klass, obj, &vid, scope, mclass); + if (m) return m; rb_method_name_error(klass, vid); } return mnew(klass, obj, id, mclass, scope); @@ -1795,10 +1802,8 @@ rb_obj_singleton_method(VALUE obj, VALUE https://github.com/ruby/ruby/blob/trunk/proc.c#L1802 obj, vid); } if (!id) { - if (respond_to_missing_p(klass, obj, vid, FALSE)) { - id = rb_intern_str(vid); - return mnew_missing(klass, obj, id, rb_cMethod); - } + VALUE m = mnew_missing_by_name(klass, obj, &vid, FALSE, rb_cMethod); + if (m) return m; goto undef; } me = rb_method_entry_at(klass, id); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/