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

ruby-changes:41621

From: nobu <ko1@a...>
Date: Sat, 30 Jan 2016 15:18:14 +0900 (JST)
Subject: [ruby-changes:41621] nobu:r53695 (trunk): vm_eval.c: fix hook call

nobu	2016-01-30 15:19:13 +0900 (Sat, 30 Jan 2016)

  New Revision: 53695

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

  Log:
    vm_eval.c: fix hook call
    
    * vm_eval.c (rb_check_funcall_with_hook): also should call the
      given hook before returning Qundef when overridden respond_to?
      method returned false.  [ruby-core:73556] [Bug #12030]

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_hash.rb
    trunk/vm_eval.c
Index: test/ruby/test_hash.rb
===================================================================
--- test/ruby/test_hash.rb	(revision 53694)
+++ test/ruby/test_hash.rb	(revision 53695)
@@ -1324,6 +1324,15 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_hash.rb#L1324
     assert_equal({dug: [:foo, :bar]}, h.dig(:d, :foo, :bar))
   end
 
+  def test_dig_with_respond_to
+    bug12030 = '[ruby-core:73556] [Bug #12030]'
+    o = Object.new
+    def o.respond_to?(*args)
+      super
+    end
+    assert_raise(TypeError) {{foo: o}.dig(:foo, :foo)}
+  end
+
   def test_cmp
     h1 = {a:1, b:2}
     h2 = {a:1, b:2, c:3}
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53694)
+++ ChangeLog	(revision 53695)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jan 30 15:18:07 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* vm_eval.c (rb_check_funcall_with_hook): also should call the
+	  given hook before returning Qundef when overridden respond_to?
+	  method returned false.  [ruby-core:73556] [Bug #12030]
+
 Fri Jan 29 17:40:07 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* win32/file.c (rb_readlink): drop garbage after the substitute
Index: vm_eval.c
===================================================================
--- vm_eval.c	(revision 53694)
+++ vm_eval.c	(revision 53695)
@@ -478,8 +478,10 @@ rb_check_funcall_with_hook(VALUE recv, I https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L478
     rb_thread_t *th = GET_THREAD();
     int respond = check_funcall_respond_to(th, klass, recv, mid);
 
-    if (!respond)
+    if (!respond) {
+	(*hook)(FALSE, recv, mid, argc, argv, arg);
 	return Qundef;
+    }
 
     me = rb_search_method_entry(recv, mid);
     if (!check_funcall_callable(th, me)) {

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

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