[前][次][番号順一覧][スレッド一覧]

ruby-changes:37178

From: nobu <ko1@a...>
Date: Thu, 15 Jan 2015 21:35:16 +0900 (JST)
Subject: [ruby-changes:37178] nobu:r49259 (trunk): proc.c: singleton_method should not use refinements

nobu	2015-01-15 21:35:00 +0900 (Thu, 15 Jan 2015)

  New Revision: 49259

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49259

  Log:
    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]

  Modified files:
    trunk/ChangeLog
    trunk/proc.c
    trunk/test/ruby/test_refinement.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 49258)
+++ ChangeLog	(revision 49259)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Jan 15 21:34:57 2015  Seiei Higa  <hanachin@g...>
+
+	* 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  <nobu@r...>
 
 	* array.c (rb_ary_select_bang, ary_reject_bang): linear
Index: proc.c
===================================================================
--- proc.c	(revision 49258)
+++ proc.c	(revision 49259)
@@ -1528,7 +1528,8 @@ rb_obj_singleton_method(VALUE obj, VALUE https://github.com/ruby/ruby/blob/trunk/proc.c#L1528
 			  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) https://github.com/ruby/ruby/blob/trunk/proc.c#L2832
     rb_define_method(rb_cBinding, "receiver", bind_receiver, 0);
     rb_define_global_function("binding", rb_f_binding, 0);
 }
-
Index: test/ruby/test_refinement.rb
===================================================================
--- test/ruby/test_refinement.rb	(revision 49258)
+++ test/ruby/test_refinement.rb	(revision 49259)
@@ -1217,6 +1217,24 @@ class TestRefinement < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_refinement.rb#L1217
     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)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]