Issue #12782 has been updated by Jeremy Evans.

Assignee set to 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.

----------------------------------------
Bug #12782: Forwardable breaks on private methods in ruby 2.4
https://bugs.ruby-lang.org/issues/12782#change-60594

* Author: Jeremy Evans
* Status: Open
* Priority: Normal
* Assignee: Yukihiro Matsumoto
* ruby -v: ruby 2.4.0preview2 (2016-09-09 trunk 56129) [i386-openbsd]
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
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:

~~~ ruby
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.





-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>