ruby-changes:18043
From: nobu <ko1@a...>
Date: Fri, 3 Dec 2010 12:20:46 +0900 (JST)
Subject: [ruby-changes:18043] Ruby:r30064 (trunk): * vm_insnhelper.c (vm_call_method): protected singleton methods should
nobu 2010-12-03 12:17:22 +0900 (Fri, 03 Dec 2010) New Revision: 30064 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=30064 Log: * vm_insnhelper.c (vm_call_method): protected singleton methods should be visible from same real class methods. [ruby-core:33506] Modified files: trunk/ChangeLog trunk/test/ruby/test_method.rb trunk/vm_insnhelper.c Index: ChangeLog =================================================================== --- ChangeLog (revision 30063) +++ ChangeLog (revision 30064) @@ -1,3 +1,8 @@ +Fri Dec 3 12:17:19 2010 Nobuyoshi Nakada <nobu@r...> + + * 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 <nobu@r...> * ext/stringio/stringio.c (strio_getline): round upto next char Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 30063) +++ vm_insnhelper.c (revision 30064) @@ -629,7 +629,10 @@ 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; } Index: test/ruby/test_method.rb =================================================================== --- test/ruby/test_method.rb (revision 30063) +++ test/ruby/test_method.rb (revision 30064) @@ -411,4 +411,23 @@ 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/