[ruby-core:62949] [ruby-trunk - Bug #9907] [Open] Abbreviated method assignment with private attr_writer/attr_reader does not work.

From: JoergWMittag+Ruby-Lang@...
Date: 2014-06-05 15:50:13 UTC
List: ruby-core #62949
Issue #9907 has been reported by J=C3=B6rg W Mittag.

----------------------------------------
Bug #9907: Abbreviated method assignment with private attr_writer/attr_read=
er does not work.
https://bugs.ruby-lang.org/issues/9907

* Author: J=C3=B6rg W Mittag
* Status: Open
* Priority: Normal
* Assignee:=20
* Category: core
* Target version: current: 2.2.0
* ruby -v: ruby 2.2.0dev (2014-06-05 trunk 46357) [x86_64-darwin13]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
This looks like a hole in the specification:

~~~
private def foo=3D(*) end
public  def foo; 0  end

self.foo =3D  42

self.foo +=3D 42
# private method `foo=3D' called for main:Object (NoMethodError)

private :foo

self.foo +=3D 42
# private method `foo' called for main:Object (NoMethodError)
~~~

There is an exception for `private` writers in the rule for private message=
 sends, but apparently that exception needs to broadened so that it also wo=
rks in the case of abbreviated assignments. I'm not entirely sure what this=
 rule would be, but I don't think it would break backwards compatibility, s=
ince all situations that would work differently with the changed rule would=
 currently raise a `NoMethodError` anyway.

The rule should be something like:

> * `private` methods can only be called without an explicit receiver.
> * An exception is made for method assignments, where the literal receiver=
 `self` is also allowed in the assignee method expression.
> * This also applies to compound assignments: `self.foo =CF=89=3D bar` sha=
ll *always* succeed if either or both of `foo` and `foo=3D` are `private`.



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

In This Thread

Prev Next