Project

General

Profile

Backport #8005

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

Added by skwosh (Alex Goldsmith) over 6 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
Normal
[ruby-core:53106]

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

Has duplicate Ruby master - Bug #8127: NoMethodError for private / protected methods with Module#prependClosed03/20/2013Actions

Associated revisions

Revision be909b5e
Added by nobu (Nobuyoshi Nakada) over 6 years ago

vm_method.c: overrid flag of prepending method

  • vm_method.c (rb_export_method): directly override the flag of method defined in prepending class too, not adding zsuper entry. [ruby-core:53106] [Bug #8005]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39743 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 39743
Added by nobu (Nobuyoshi Nakada) over 6 years ago

vm_method.c: overrid flag of prepending method

  • vm_method.c (rb_export_method): directly override the flag of method defined in prepending class too, not adding zsuper entry. [ruby-core:53106] [Bug #8005]

Revision 39743
Added by nobu (Nobuyoshi Nakada) over 6 years ago

vm_method.c: overrid flag of prepending method

  • vm_method.c (rb_export_method): directly override the flag of method defined in prepending class too, not adding zsuper entry. [ruby-core:53106] [Bug #8005]

Revision 39743
Added by nobu (Nobuyoshi Nakada) over 6 years ago

vm_method.c: overrid flag of prepending method

  • vm_method.c (rb_export_method): directly override the flag of method defined in prepending class too, not adding zsuper entry. [ruby-core:53106] [Bug #8005]

Revision 39743
Added by nobu (Nobuyoshi Nakada) over 6 years ago

vm_method.c: overrid flag of prepending method

  • vm_method.c (rb_export_method): directly override the flag of method defined in prepending class too, not adding zsuper entry. [ruby-core:53106] [Bug #8005]

Revision 39743
Added by nobu (Nobuyoshi Nakada) over 6 years ago

vm_method.c: overrid flag of prepending method

  • vm_method.c (rb_export_method): directly override the flag of method defined in prepending class too, not adding zsuper entry. [ruby-core:53106] [Bug #8005]

Revision 39743
Added by nobu (Nobuyoshi Nakada) over 6 years ago

vm_method.c: overrid flag of prepending method

  • vm_method.c (rb_export_method): directly override the flag of method defined in prepending class too, not adding zsuper entry. [ruby-core:53106] [Bug #8005]

Revision 047b5539
Added by nagachika (Tomoyuki Chikanaga) over 6 years 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.
* vm_method.c (rb_export_method): directly override the flag of method
defined in prepending class too, not adding zsuper entry.
[ruby-core:53106] [Bug #8005]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@40252 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 40252
Added by nagachika (Tomoyuki Chikanaga) over 6 years 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.
* vm_method.c (rb_export_method): directly override the flag of method
defined in prepending class too, not adding zsuper entry.
[ruby-core:53106] [Bug #8005]

History

#1

Updated by nobu (Nobuyoshi Nakada) over 6 years 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

  • vm_method.c (rb_export_method): directly override the flag of method defined in prepending class too, not adding zsuper entry. [ruby-core:53106] [Bug #8005]
#2

Updated by nobu (Nobuyoshi Nakada) over 6 years ago

  • Tracker changed from Bug to Backport
  • Project changed from Ruby master to Backport200
  • Status changed from Closed to Assigned
  • Assignee set to nagachika (Tomoyuki Chikanaga)
#3

Updated by nagachika (Tomoyuki Chikanaga) over 6 years 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.
* vm_method.c (rb_export_method): directly override the flag of method
defined in prepending class too, not adding zsuper entry.
[ruby-core:53106] [Bug #8005]

Also available in: Atom PDF