From adc978adc3932e5fdeb0bdc0622d2f52bf846dba Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 3 Dec 2010 03:17:22 +0000 Subject: [PATCH] * vm_insnhelper.c (vm_call_method): protected singleton methods should be visible from same real class methods. [ruby-core:33506] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30064 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ test/ruby/test_method.rb | 19 +++++++++++++++++++ vm_insnhelper.c | 5 ++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 7c039617f9..7b732baf62 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Dec 3 12:17:19 2010 Nobuyoshi Nakada + + * vm_insnhelper.c (vm_call_method): protected singleton methods should + be visible from same real class methods. [ruby-core:33506] + Fri Dec 3 07:08:42 2010 Nobuyoshi Nakada * ext/stringio/stringio.c (strio_getline): round upto next char diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb index da17ef5e9c..2f3ba3ebd6 100644 --- a/test/ruby/test_method.rb +++ b/test/ruby/test_method.rb @@ -411,4 +411,23 @@ class TestMethod < Test::Unit::TestCase assert_nothing_raised { v.instance_eval { mv2 } } assert_nothing_raised { v.instance_eval { mv3 } } end + + def test_protected_singleton + bug4106 = '[ruby-core:33506]' + a = Class.new do + def meth + :called + end + def test + a = dup + class << a + protected :meth + end + a.meth + end + end.new + called = nil + assert_nothing_raised(NoMethodError, bug4106) {called = a.test} + assert_equal(:called, called, bug4106) + end end diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 18c22cb81d..6ec6026e37 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -629,7 +629,10 @@ vm_call_method(rb_thread_t *th, rb_control_frame_t *cfp, else if (!(flag & VM_CALL_OPT_SEND_BIT) && (me->flag & NOEX_MASK) & NOEX_PROTECTED) { VALUE defined_class = me->klass; - if (TYPE(defined_class) == T_ICLASS) { + if (FL_TEST(defined_class, FL_SINGLETON)) { + defined_class = RCLASS_SUPER(defined_class); + } + else if (RB_TYPE_P(defined_class, T_ICLASS)) { defined_class = RBASIC(defined_class)->klass; }