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

ruby-changes:44621

From: nobu <ko1@a...>
Date: Thu, 10 Nov 2016 23:18:57 +0900 (JST)
Subject: [ruby-changes:44621] nobu:r56694 (trunk): vm_eval.c: fix refined method when prepended

nobu	2016-11-10 23:18:52 +0900 (Thu, 10 Nov 2016)

  New Revision: 56694

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

  Log:
    vm_eval.c: fix refined method when prepended
    
    * vm_eval.c (vm_call0_body): refined module should not be skipped
      as prepended.  [ruby-core:78073] [Bug #12920]

  Modified files:
    trunk/test/ruby/test_refinement.rb
    trunk/vm_eval.c
Index: vm_eval.c
===================================================================
--- vm_eval.c	(revision 56693)
+++ vm_eval.c	(revision 56694)
@@ -194,14 +194,19 @@ vm_call0_body(rb_thread_t* th, struct rb https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L194
       case VM_METHOD_TYPE_REFINED:
 	{
 	    const rb_method_type_t type = cc->me->def->type;
-	    VALUE super_class;
+	    VALUE super_class = cc->me->defined_class;
 
-	    if (type == VM_METHOD_TYPE_REFINED && cc->me->def->body.refined.orig_me) {
-		cc->me = refined_method_callable_without_refinement(cc->me);
-		goto again;
+	    if (type == VM_METHOD_TYPE_REFINED) {
+		if (cc->me->def->body.refined.orig_me) {
+		    cc->me = refined_method_callable_without_refinement(cc->me);
+		    goto again;
+		}
+	    }
+	    else {
+		super_class = RCLASS_ORIGIN(super_class);
 	    }
 
-	    super_class = RCLASS_SUPER(RCLASS_ORIGIN(cc->me->defined_class));
+	    super_class = RCLASS_SUPER(super_class);
 
 	    if (!super_class || !(cc->me = rb_callable_method_entry(super_class, ci->mid))) {
 		enum method_missing_reason ex = (type == VM_METHOD_TYPE_ZSUPER) ? MISSING_SUPER : 0;
Index: test/ruby/test_refinement.rb
===================================================================
--- test/ruby/test_refinement.rb	(revision 56693)
+++ test/ruby/test_refinement.rb	(revision 56694)
@@ -1775,6 +1775,20 @@ class TestRefinement < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_refinement.rb#L1775
                  eval_using(AliasInSubclass::M, "AliasInSubclass::D.new.bar"))
   end
 
+  def test_refine_with_prepend
+    assert_separately([], "#{<<-"begin;"}\n#{<<-"end;"}")
+    begin;
+      bug = '[ruby-core:78073] [Bug #12920]'
+      Integer.prepend(Module.new)
+      Module.new do
+        refine Integer do
+          define_method(:+) {}
+        end
+      end
+      assert_kind_of(Time, Time.now, bug)
+    end;
+  end
+
   private
 
   def eval_using(mod, s)

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

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