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

ruby-changes:32448

From: nobu <ko1@a...>
Date: Wed, 8 Jan 2014 22:53:33 +0900 (JST)
Subject: [ruby-changes:32448] nobu:r44527 (trunk): vm_insnhelper.c: revive r44455 for bound module method

nobu	2014-01-08 22:53:18 +0900 (Wed, 08 Jan 2014)

  New Revision: 44527

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

  Log:
    vm_insnhelper.c: revive r44455 for bound module method
    
    * vm_insnhelper.c (vm_search_super_method): when super called in a
      bound UnboundMethod generated from a module, no superclass is
      found since the current defined class is the module, then call
      method_missing in that case.  [ruby-core:59619] [Bug #9377]

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_super.rb
    trunk/vm_insnhelper.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44526)
+++ ChangeLog	(revision 44527)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jan  8 22:53:16 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* vm_insnhelper.c (vm_search_super_method): when super called in a
+	  bound UnboundMethod generated from a module, no superclass is
+	  found since the current defined class is the module, then call
+	  method_missing in that case.  [ruby-core:59619] [Bug #9377]
+
 Wed Jan  8 15:55:21 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* hash.c (rb_objid_hash): return hash value from object ID with a
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 44526)
+++ vm_insnhelper.c	(revision 44527)
@@ -2024,6 +2024,12 @@ vm_search_super_method(rb_thread_t *th, https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L2024
 		 " by define_method() is not supported."
 		 " Specify all arguments explicitly.");
     }
+    if (!ci->klass) {
+	/* bound instance method of module */
+	ci->aux.missing_reason = NOEX_SUPER;
+	CI_SET_FASTPATH(ci, vm_call_method_missing, 1);
+	return;
+    }
 
     /* TODO: use inline cache */
     ci->me = rb_method_entry(ci->klass, ci->mid, &ci->defined_class);
Index: test/ruby/test_super.rb
===================================================================
--- test/ruby/test_super.rb	(revision 44526)
+++ test/ruby/test_super.rb	(revision 44527)
@@ -440,4 +440,17 @@ class TestSuper < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_super.rb#L440
       assert_equal(:ok, o.method(:foo).call, bug9315)
     end
   end
+
+  def test_missing_super_in_module_unbound_method
+    bug9377 = '[ruby-core:59619] [Bug #9377]'
+
+    a = Module.new do
+      def foo; super end
+    end
+
+    m = a.instance_method(:foo).bind(Object.new.extend(a))
+    assert_raise(NoMethodError, bug9377) do
+      m.call
+    end
+  end
 end

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

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