Project

General

Profile

Actions

Bug #4106

closed

1.9.2 regression - invoking protected singleton methods

Added by dmendel (Dion Mendel) over 13 years ago. Updated about 13 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]
Backport:
[ruby-core:33506]

Description

=begin
Issue:

Invoking a method that has been made protected in an object's
singleton class fails with
NoMethodError: protected method `xxxx' called.

Invoking this protected method succeeds in 1.8.7 and 1.9.1.

Relevant code snippet:

class < a
  protected :meth
end

Test case:

In 1.8.7 and 1.9.1, code will output "method called"
In 1.9.2 code raises NoMethodError test.rb:13:in test': protected method meth' called for #<A:0x91477d4>


class A
def meth
puts 'method called'
end

def test
a = A.new

 class << a
   protected :meth
 end

 a.meth  # fails in 1.9.2

end
end

a = A.new
a.test
=end


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #2375: protected singleton methods can be called from other instancesClosedmatz (Yukihiro Matsumoto)11/16/2009Actions
Actions #1

Updated by nobu (Nobuyoshi Nakada) over 13 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
This issue was solved with changeset r30064.
Dion, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

=end

Actions #2

Updated by nagachika (Tomoyuki Chikanaga) over 13 years ago

=begin
Hi

After r30064, invoking method still cause NoMethodError if an object has been 'extend'ed.

-- test code
module M
end
class A
def meth
:called
end
def test
a = dup
a.extend M
class << a
protected :meth
end
a.meth
end
end

o = A.new
p o.test

-- patch
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 6ec6026..968bf10 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -630,7 +630,9 @@ vm_call_method(rb_thread_t *th, rb_control_frame_t *cfp,
VALUE defined_class = me->klass;

             if (FL_TEST(defined_class, FL_SINGLETON)) {
  •               defined_class = RCLASS_SUPER(defined_class);
    
  •               do {
    
  •                   defined_class = RCLASS_SUPER(defined_class);
    
  •               } while(RB_TYPE_P(defined_class, T_ICLASS));
              }
              else if (RB_TYPE_P(defined_class, T_ICLASS)) {
                  defined_class = RBASIC(defined_class)->klass;
    

=end

Actions #3

Updated by nobu (Nobuyoshi Nakada) over 13 years ago

  • Status changed from Closed to Rejected

=begin

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0