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

ruby-changes:38656

From: ko1 <ko1@a...>
Date: Wed, 3 Jun 2015 04:36:57 +0900 (JST)
Subject: [ruby-changes:38656] ko1:r50737 (trunk): * vm_insnhelper.c (vm_defined): skip respond_to_missing? when

ko1	2015-06-03 04:36:43 +0900 (Wed, 03 Jun 2015)

  New Revision: 50737

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

  Log:
    * vm_insnhelper.c (vm_defined): skip respond_to_missing? when
      a method is available.
      [Bug #11211]
    * test/ruby/test_defined.rb: add a test for this fix.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_defined.rb
    trunk/vm_insnhelper.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 50736)
+++ ChangeLog	(revision 50737)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jun  3 04:34:39 2015  Koichi Sasada  <ko1@a...>
+
+	* vm_insnhelper.c (vm_defined): skip respond_to_missing? when
+	  a method is available.
+	  [Bug #11211]
+
+	* test/ruby/test_defined.rb: add a test for this fix.
+
 Wed Jun  3 04:14:13 2015  Koichi Sasada  <ko1@a...>
 
 	* insns.def (defined), vm_insnhelper.c (vm_defined):
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 50736)
+++ vm_insnhelper.c	(revision 50737)
@@ -2456,15 +2456,12 @@ vm_defined(rb_thread_t *th, rb_control_f https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L2456
 
 	if (me) {
 	    const rb_method_definition_t *def = me->def;
-	    if (!(def->flag & NOEX_PRIVATE)) {
-		if (!((def->flag & NOEX_PROTECTED) &&
-		      !rb_obj_is_kind_of(GET_SELF(),
-					 rb_class_real(klass)))) {
-		    expr_type = DEFINED_METHOD;
-		}
+	    if (!(def->flag & NOEX_PRIVATE) &&
+		!((def->flag & NOEX_PROTECTED) && !rb_obj_is_kind_of(GET_SELF(), rb_class_real(klass)))) {
+		expr_type = DEFINED_METHOD;
 	    }
 	}
-	{
+	else {
 	    VALUE args[2];
 	    VALUE r;
 
Index: test/ruby/test_defined.rb
===================================================================
--- test/ruby/test_defined.rb	(revision 50736)
+++ test/ruby/test_defined.rb	(revision 50737)
@@ -208,4 +208,29 @@ class TestDefined < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_defined.rb#L208
   def test_super_toplevel
     assert_separately([], "assert_nil(defined?(super))")
   end
+
+  class ExampleRespondToMissing
+    attr_reader :called
+
+    def initialize
+      @called = false
+    end
+
+    def respond_to_missing? *args
+      @called = true
+      false
+    end
+
+    def existing_method
+    end
+  end
+
+  def test_method_by_respond_to_missing
+    bug_11211 = '[Bug #11211]'
+    obj = ExampleRespondToMissing.new
+    assert_equal("method", defined?(obj.existing_method), bug_11211)
+    assert_equal(false, obj.called, bug_11211)
+    assert_equal(nil, defined?(obj.non_existing_method), bug_11211)
+    assert_equal(true, obj.called, bug_11211)
+  end
 end

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

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