Backport #8005

Methods made private/protected after definition are made uncallable by prepend

Added by Alex Goldsmith about 1 year ago. Updated about 1 year ago.

[ruby-core:53106]
Status:Closed
Priority:Normal
Assignee:Tomoyuki Chikanaga

Description

Prepending a module seems to break method resolution for methods that have been made private or protected via the def private *names and def protected *names methods.


class A
end

A.send :prepend, Module.new {} # Works if this line is removed...

class A
def foo() end
protected :foo # Also works if we use the argument-less form of "protected"...
end

A.new.respond_to? :foo, true # => true

A.new.send :foo # => NoMethodError: undefined method `foo' for #


Note that it correctly reports that it can respond_to?...

This breaks in Rails 4 when trying to prepend to an ActiveRecord::Base (due to dynamically defined model callbacks).


Related issues

Duplicated by ruby-trunk - Bug #8127: NoMethodError for private / protected methods with Module... Closed 03/20/2013

Associated revisions

Revision 40252
Added by Tomoyuki Chikanaga about 1 year ago

merge revision(s) 39742,39743: [Backport #8005]

assertions.rb: private flag

* lib/test/unit/assertions.rb (assert_respond_to): accept optional

include-private flag.
* vmmethod.c (rbexport_method): directly override the flag of method
defined in prepending class too, not adding zsuper entry.
[Bug #8005]

History

#1 Updated by Nobuyoshi Nakada about 1 year ago

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

This issue was solved with changeset r39743.
Alex, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


vm_method.c: overrid flag of prepending method

  • vmmethod.c (rbexport_method): directly override the flag of method defined in prepending class too, not adding zsuper entry. [Bug #8005]

#2 Updated by Nobuyoshi Nakada about 1 year ago

  • Tracker changed from Bug to Backport
  • Project changed from ruby-trunk to Backport200
  • Status changed from Closed to Assigned
  • Assignee set to Tomoyuki Chikanaga

#3 Updated by Tomoyuki Chikanaga about 1 year ago

  • Status changed from Assigned to Closed

This issue was solved with changeset r40252.
Alex, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


merge revision(s) 39742,39743: [Backport #8005]

assertions.rb: private flag

* lib/test/unit/assertions.rb (assert_respond_to): accept optional

include-private flag.
* vmmethod.c (rbexport_method): directly override the flag of method
defined in prepending class too, not adding zsuper entry.
[Bug #8005]

Also available in: Atom PDF