From 0fce0b7ba1337b25d717fc39481eef556d247005 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 15 Jan 2015 12:35:00 +0000 Subject: proc.c: singleton_method should not use refinements * proc.c (rb_obj_singleton_method): Kernel#singleton_method should not use refinements, as well as Kernel#method. [ruby-core:67603] [Bug #10744] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ proc.c | 4 ++-- test/ruby/test_refinement.rb | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8b963e5df5..3e4bb457a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Thu Jan 15 21:34:57 2015 Seiei Higa + + * proc.c (rb_obj_singleton_method): Kernel#singleton_method should + not use refinements, as well as Kernel#method. + [ruby-core:67603] [Bug #10744] + Thu Jan 15 10:45:04 2015 Nobuyoshi Nakada * array.c (rb_ary_select_bang, ary_reject_bang): linear diff --git a/proc.c b/proc.c index 805f7b9603..48d7dcb490 100644 --- a/proc.c +++ b/proc.c @@ -1528,7 +1528,8 @@ rb_obj_singleton_method(VALUE obj, VALUE vid) QUOTE(vid), obj); } if (NIL_P(klass = rb_singleton_class_get(obj)) || - !(me = rb_method_entry_at(klass, id))) { + UNDEFINED_METHOD_ENTRY_P(me = rb_method_entry_at(klass, id)) || + UNDEFINED_REFINED_METHOD_P(me->def)) { rb_name_error(id, "undefined singleton method `%"PRIsVALUE"' for `%"PRIsVALUE"'", QUOTE_ID(id), obj); } @@ -2831,4 +2832,3 @@ Init_Binding(void) rb_define_method(rb_cBinding, "receiver", bind_receiver, 0); rb_define_global_function("binding", rb_f_binding, 0); } - diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb index 884d031c87..596c679610 100644 --- a/test/ruby/test_refinement.rb +++ b/test/ruby/test_refinement.rb @@ -1217,6 +1217,24 @@ class TestRefinement < Test::Unit::TestCase end; end + def test_singleton_method_should_not_use_refinements + assert_separately([], <<-"end;") + bug10744 = '[ruby-core:67603] [Bug #10744]' + + class C + end + + module RefinementBug + refine C.singleton_class do + def foo + end + end + end + + assert_raise(NameError, bug10744) { C.singleton_method(:foo) } + end; + end + private def eval_using(mod, s) -- cgit v1.2.3