Project

General

Profile

Bug #12782

Forwardable breaks on private methods in ruby 2.4

Added by jeremyevans0 (Jeremy Evans) almost 3 years ago. Updated almost 3 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 2.4.0preview2 (2016-09-09 trunk 56129) [i386-openbsd]
[ruby-core:77341]

Description

Due to an optimization in r55376, attempting to forward to private methods no longer works in ruby 2.4. Among other things, this breaks haml template support in tilt. Example:

require 'forwardable'
class Foo
  private def foo; :foo end
  extend Forwardable
  def_delegator :itself, :foo, :bar
end
p Foo.new.bar

On ruby 2.3, this outputs :foo, on 2.4.0preview2 it raises NoMethodError. I think r55376 should be reverted, as the optimization it uses does not appear to be able to handle private method calls.

Associated revisions

Revision ef13e60f
Added by nobu (Nobuyoshi Nakada) almost 3 years ago

forwardable.rb: private methods

  • lib/forwardable.rb (_delegator_method): allow private methods to be delegated, with warnings. [ruby-core:77341] [Bug #12782]

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

Revision 56210
Added by nobu (Nobuyoshi Nakada) almost 3 years ago

forwardable.rb: private methods

  • lib/forwardable.rb (_delegator_method): allow private methods to be delegated, with warnings. [ruby-core:77341] [Bug #12782]

Revision 56210
Added by nobu (Nobuyoshi Nakada) almost 3 years ago

forwardable.rb: private methods

  • lib/forwardable.rb (_delegator_method): allow private methods to be delegated, with warnings. [ruby-core:77341] [Bug #12782]

Revision 56210
Added by nobu (Nobuyoshi Nakada) almost 3 years ago

forwardable.rb: private methods

  • lib/forwardable.rb (_delegator_method): allow private methods to be delegated, with warnings. [ruby-core:77341] [Bug #12782]

Revision 56210
Added by nobu (Nobuyoshi Nakada) almost 3 years ago

forwardable.rb: private methods

  • lib/forwardable.rb (_delegator_method): allow private methods to be delegated, with warnings. [ruby-core:77341] [Bug #12782]

Revision 58c5011b
Added by shyouhei (Shyouhei Urabe) almost 3 years ago

  • test/test_forwardable.rb (TestForwardable#test_on_private_method): add test for [Bug #12782] [Bug #12840]

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

Revision 56530
Added by shyouhei (Shyouhei Urabe) almost 3 years ago

  • test/test_forwardable.rb (TestForwardable#test_on_private_method): add test for [Bug #12782] [Bug #12840]

Revision 56530
Added by shyouhei (Shyouhei Urabe) almost 3 years ago

  • test/test_forwardable.rb (TestForwardable#test_on_private_method): add test for [Bug #12782] [Bug #12840]

Revision 56530
Added by shyouhei (Shyouhei Urabe) almost 3 years ago

  • test/test_forwardable.rb (TestForwardable#test_on_private_method): add test for [Bug #12782] [Bug #12840]

Revision 56530
Added by shyouhei (Shyouhei Urabe) almost 3 years ago

  • test/test_forwardable.rb (TestForwardable#test_on_private_method): add test for [Bug #12782] [Bug #12840]

History

Updated by nobu (Nobuyoshi Nakada) almost 3 years ago

I suspect that it was a bug to able to delegate a private method.

Updated by jeremyevans0 (Jeremy Evans) almost 3 years ago

  • Assignee set to matz (Yukihiro Matsumoto)

Nobuyoshi Nakada wrote:

I suspect that it was a bug to able to delegate a private method.

It does seem like a bad idea to allow forwarding to private methods. However, the commit message did not mention that it fixes a bug, so I believe the behavior change was unintentional. Allowing delegating to private methods dates to forwardable's initial commit (in ruby 1.6), and there are ruby libraries relying on this behavior (tilt's haml support at least). Assigning to matz to make a decision on whether to break backwards compatibility.

Updated by marcandre (Marc-Andre Lafortune) almost 3 years ago

The choice might be more between simply reverting and reverting but adding code to detect private calls and issue a deprecation warning so we can reintroduce the optimization in another version.

#4

Updated by nobu (Nobuyoshi Nakada) almost 3 years ago

  • Status changed from Open to Closed

Applied in changeset r56210.


forwardable.rb: private methods

  • lib/forwardable.rb (_delegator_method): allow private methods to be delegated, with warnings. [ruby-core:77341] [Bug #12782]

Also available in: Atom PDF