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

ruby-changes:37140

From: nobu <ko1@a...>
Date: Mon, 12 Jan 2015 16:46:02 +0900 (JST)
Subject: [ruby-changes:37140] nobu:r49221 (trunk): vm_method.c: NameError at refined method alias

nobu	2015-01-12 16:45:49 +0900 (Mon, 12 Jan 2015)

  New Revision: 49221

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

  Log:
    vm_method.c: NameError at refined method alias
    
    * vm_method.c (rb_alias): raise a NameError when creating alias to
      a refined method if the original method of the refined method is
      not defined.  [ruby-core:67523] [Bug #10731]

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_refinement.rb
    trunk/vm_method.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 49220)
+++ ChangeLog	(revision 49221)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Jan 12 16:45:46 2015  Seiei Higa  <hanachin@g...>
+
+	* vm_method.c (rb_alias): raise a NameError when creating alias to
+	  a refined method if the original method of the refined method is
+	  not defined.  [ruby-core:67523] [Bug #10731]
+
 Mon Jan 12 13:53:17 2015  SHIBATA Hiroshi  <shibata.hiroshi@g...>
 
 	* math.c (math_atan2): improve documentation.
Index: vm_method.c
===================================================================
--- vm_method.c	(revision 49220)
+++ vm_method.c	(revision 49221)
@@ -1278,7 +1278,9 @@ rb_alias(VALUE klass, ID name, ID def) https://github.com/ruby/ruby/blob/trunk/vm_method.c#L1278
   again:
     orig_me = search_method(klass, def, &defined_class);
 
-    if (UNDEFINED_METHOD_ENTRY_P(orig_me)) {
+    if (UNDEFINED_METHOD_ENTRY_P(orig_me) ||
+	(orig_me->def->type == VM_METHOD_TYPE_REFINED &&
+	 UNDEFINED_METHOD_ENTRY_P(orig_me->def->body.orig_me))) {
 	if ((!RB_TYPE_P(klass, T_MODULE)) ||
 	    (orig_me = search_method(rb_cObject, def, 0),
 	     UNDEFINED_METHOD_ENTRY_P(orig_me))) {
Index: test/ruby/test_refinement.rb
===================================================================
--- test/ruby/test_refinement.rb	(revision 49220)
+++ test/ruby/test_refinement.rb	(revision 49221)
@@ -1192,6 +1192,31 @@ class TestRefinement < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_refinement.rb#L1192
     end;
   end
 
+  def test_alias_refined_method
+    assert_separately([], <<-"end;")
+    bug10731 = '[ruby-core:67523] [Bug #10731]'
+
+    class C
+    end
+
+    module RefinementBug
+      refine C do
+        def foo
+        end
+
+        def bar
+        end
+      end
+    end
+
+    assert_raise(NameError, bug10731) do
+      class C
+        alias foo bar
+      end
+    end
+    end;
+  end
+
   private
 
   def eval_using(mod, s)

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

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