ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:68502] [Ruby trunk - Bug #10967] [Open] Is "warning: private attribute?" wrong?
       [not found] <redmine.issue-10967.20150311200640@ruby-lang.org>
@ 2015-03-11 20:06 ` santiago
  2015-03-12 15:03 ` [ruby-core:68510] [Ruby trunk - Bug #10967] " santiago
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: santiago @ 2015-03-11 20:06 UTC (permalink / raw)
  To: ruby-core

Issue #10967 has been reported by Santiago Pastorino.

----------------------------------------
Bug #10967: Is "warning: private attribute?" wrong?
https://bugs.ruby-lang.org/issues/10967

* Author: Santiago Pastorino
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.3.0dev (2015-03-01 trunk 49796) [x86_64-darwin14]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
The following code ...

```
class Y
  def initialize
    @x = "ZOMG"
  end

  def print_x
    puts x
  end

  private

  attr_reader :x
end

Y.new.print_x
```

outputs ...

```
test.rb:12: warning: private attribute?
```

I tend to think this warning is wrong, I was surprised by https://github.com/rack/rack/pull/811 and I think this is a completely valid use case.

Also this code ...

```
class Y
  def initialize
    @x = "ZOMG"
  end

  def print_x
    puts x
  end

  def assign_x
    self.x = "ZOMG ZOMG"
  end

  private

  attr_accessor :x
end

y = Y.new
y.assign_x
y.print_x
```

Works fine with warnings also. So a private writer works ok when the receiver is `self` because Ruby has a special case for it, this make me think that private writers were thought to be used.

So ... am I wrong thinking that the warning should be removed or the self special case shouldn't work and be removed from Ruby code?. It doesn't make sense to me to have both things.



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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:68510] [Ruby trunk - Bug #10967] Is "warning: private attribute?" wrong?
       [not found] <redmine.issue-10967.20150311200640@ruby-lang.org>
  2015-03-11 20:06 ` [ruby-core:68502] [Ruby trunk - Bug #10967] [Open] Is "warning: private attribute?" wrong? santiago
@ 2015-03-12 15:03 ` santiago
  2015-03-28  8:36   ` [ruby-core:68667] Re: [Ruby trunk - Bug #10967] [Open] " Zachary Scott
  2015-04-27 22:42 ` [ruby-core:69005] [Ruby trunk - Bug #10967] " nobu
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 11+ messages in thread
From: santiago @ 2015-03-12 15:03 UTC (permalink / raw)
  To: ruby-core

Issue #10967 has been updated by Santiago Pastorino.


One possible fix (the one removing the warning) ... https://github.com/ruby/ruby/pull/849

----------------------------------------
Bug #10967: Is "warning: private attribute?" wrong?
https://bugs.ruby-lang.org/issues/10967#change-51839

* Author: Santiago Pastorino
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.3.0dev (2015-03-01 trunk 49796) [x86_64-darwin14]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
The following code ...

```
class Y
  def initialize
    @x = "ZOMG"
  end

  def print_x
    puts x
  end

  private

  attr_reader :x
end

Y.new.print_x
```

outputs ...

```
test.rb:12: warning: private attribute?
```

I tend to think this warning is wrong, I was surprised by https://github.com/rack/rack/pull/811 and I think this is a completely valid use case.

Also this code ...

```
class Y
  def initialize
    @x = "ZOMG"
  end

  def print_x
    puts x
  end

  def assign_x
    self.x = "ZOMG ZOMG"
  end

  private

  attr_accessor :x
end

y = Y.new
y.assign_x
y.print_x
```

Works fine with warnings also. So a private writer works ok when the receiver is `self` because Ruby has a special case for it, this make me think that private writers were thought to be used.

So ... am I wrong thinking that the warning should be removed or the self special case shouldn't work and be removed from Ruby code?. It doesn't make sense to me to have both things.



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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:68667] Re: [Ruby trunk - Bug #10967] [Open] Is "warning: private attribute?" wrong?
  2015-03-12 15:03 ` [ruby-core:68510] [Ruby trunk - Bug #10967] " santiago
@ 2015-03-28  8:36   ` Zachary Scott
  0 siblings, 0 replies; 11+ messages in thread
From: Zachary Scott @ 2015-03-28  8:36 UTC (permalink / raw)
  To: Ruby developers

[-- Attachment #1: Type: text/plain, Size: 1994 bytes --]

I'd like to know the intention behind this warning.. but so far haven't
seen it.

Also, since this behavior was added in a minor release, we can't really
change it now until the next major.. IF we care about semver for this,
which may not be the case

On Thursday, March 12, 2015, <santiago@wyeworks.com> wrote:

> Issue #10967 has been updated by Santiago Pastorino.
>
>
> One possible fix (the one removing the warning) ...
> https://github.com/ruby/ruby/pull/849
>
> ----------------------------------------
> Bug #10967: Is "warning: private attribute?" wrong?
> https://bugs.ruby-lang.org/issues/10967#change-51839
>
> * Author: Santiago Pastorino
> * Status: Open
> * Priority: Normal
> * Assignee:
> * ruby -v: ruby 2.3.0dev (2015-03-01 trunk 49796) [x86_64-darwin14]
> * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
> ----------------------------------------
> The following code ...
>
> ```
> class Y
>   def initialize
>     @x = "ZOMG"
>   end
>
>   def print_x
>     puts x
>   end
>
>   private
>
>   attr_reader :x
> end
>
> Y.new.print_x
> ```
>
> outputs ...
>
> ```
> test.rb:12: warning: private attribute?
> ```
>
> I tend to think this warning is wrong, I was surprised by
> https://github.com/rack/rack/pull/811 and I think this is a completely
> valid use case.
>
> Also this code ...
>
> ```
> class Y
>   def initialize
>     @x = "ZOMG"
>   end
>
>   def print_x
>     puts x
>   end
>
>   def assign_x
>     self.x = "ZOMG ZOMG"
>   end
>
>   private
>
>   attr_accessor :x
> end
>
> y = Y.new
> y.assign_x
> y.print_x
> ```
>
> Works fine with warnings also. So a private writer works ok when the
> receiver is `self` because Ruby has a special case for it, this make me
> think that private writers were thought to be used.
>
> So ... am I wrong thinking that the warning should be removed or the self
> special case shouldn't work and be removed from Ruby code?. It doesn't make
> sense to me to have both things.
>
>
>
> --
> https://bugs.ruby-lang.org/
>

[-- Attachment #2: Type: text/html, Size: 2817 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:69005] [Ruby trunk - Bug #10967] Is "warning: private attribute?" wrong?
       [not found] <redmine.issue-10967.20150311200640@ruby-lang.org>
  2015-03-11 20:06 ` [ruby-core:68502] [Ruby trunk - Bug #10967] [Open] Is "warning: private attribute?" wrong? santiago
  2015-03-12 15:03 ` [ruby-core:68510] [Ruby trunk - Bug #10967] " santiago
@ 2015-04-27 22:42 ` nobu
  2015-04-28  0:25 ` [ruby-core:69007] " ruby-core
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: nobu @ 2015-04-27 22:42 UTC (permalink / raw)
  To: ruby-core

Issue #10967 has been updated by Nobuyoshi Nakada.

Description updated

It's valid in your case, but may not in others.
It doesn't sound enough reason to remove that warning to me.

If you want to suppress the warning, you can explicitly do it after the definition.

```ruby
class Y
  attr_writer :x
  private :x=
end
```



----------------------------------------
Bug #10967: Is "warning: private attribute?" wrong?
https://bugs.ruby-lang.org/issues/10967#change-52261

* Author: Santiago Pastorino
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.3.0dev (2015-03-01 trunk 49796) [x86_64-darwin14]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
The following code ...

```ruby
class Y
  def initialize
    @x = "ZOMG"
  end

  def print_x
    puts x
  end

  private

  attr_reader :x
end

Y.new.print_x
```

outputs ...

```
test.rb:12: warning: private attribute?
```

I tend to think this warning is wrong, I was surprised by https://github.com/rack/rack/pull/811 and I think this is a completely valid use case.

Also this code ...

```ruby
class Y
  def initialize
    @x = "ZOMG"
  end

  def print_x
    puts x
  end

  def assign_x
    self.x = "ZOMG ZOMG"
  end

  private

  attr_accessor :x
end

y = Y.new
y.assign_x
y.print_x
```

Works fine with warnings also. So a private writer works ok when the receiver is `self` because Ruby has a special case for it, this make me think that private writers were thought to be used.

So ... am I wrong thinking that the warning should be removed or the self special case shouldn't work and be removed from Ruby code?. It doesn't make sense to me to have both things.



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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:69007] [Ruby trunk - Bug #10967] Is "warning: private attribute?" wrong?
       [not found] <redmine.issue-10967.20150311200640@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2015-04-27 22:42 ` [ruby-core:69005] [Ruby trunk - Bug #10967] " nobu
@ 2015-04-28  0:25 ` ruby-core
  2015-04-30 18:23 ` [ruby-core:69042] " santiago
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: ruby-core @ 2015-04-28  0:25 UTC (permalink / raw)
  To: ruby-core

Issue #10967 has been updated by Marc-Andre Lafortune.


FWIW, I feel that warning should be removed. There are too many false positives, and I suspect very very few cases where that warning is of any help. Note that without the warning, it will be obvious anyways when calling that reader/writer that it fails because it is private.

----------------------------------------
Bug #10967: Is "warning: private attribute?" wrong?
https://bugs.ruby-lang.org/issues/10967#change-52263

* Author: Santiago Pastorino
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.3.0dev (2015-03-01 trunk 49796) [x86_64-darwin14]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
The following code ...

```ruby
class Y
  def initialize
    @x = "ZOMG"
  end

  def print_x
    puts x
  end

  private

  attr_reader :x
end

Y.new.print_x
```

outputs ...

```
test.rb:12: warning: private attribute?
```

I tend to think this warning is wrong, I was surprised by https://github.com/rack/rack/pull/811 and I think this is a completely valid use case.

Also this code ...

```ruby
class Y
  def initialize
    @x = "ZOMG"
  end

  def print_x
    puts x
  end

  def assign_x
    self.x = "ZOMG ZOMG"
  end

  private

  attr_accessor :x
end

y = Y.new
y.assign_x
y.print_x
```

Works fine with warnings also. So a private writer works ok when the receiver is `self` because Ruby has a special case for it, this make me think that private writers were thought to be used.

So ... am I wrong thinking that the warning should be removed or the self special case shouldn't work and be removed from Ruby code?. It doesn't make sense to me to have both things.



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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:69042] [Ruby trunk - Bug #10967] Is "warning: private attribute?" wrong?
       [not found] <redmine.issue-10967.20150311200640@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2015-04-28  0:25 ` [ruby-core:69007] " ruby-core
@ 2015-04-30 18:23 ` santiago
  2015-05-14  7:00 ` [ruby-core:69186] " matz
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: santiago @ 2015-04-30 18:23 UTC (permalink / raw)
  To: ruby-core

Issue #10967 has been updated by Santiago Pastorino.


There's also a discussion going on in another PR, https://github.com/ruby/ruby/pull/889

@nobu, not sure what are the invalid use cases you refer to, and also what if I need to use let's say 2 private accessors? should I do ...

```
  attr_accessor :a, :b

  private :a, :a=, :b, :b=
```
Doesn't sound great to me.

----------------------------------------
Bug #10967: Is "warning: private attribute?" wrong?
https://bugs.ruby-lang.org/issues/10967#change-52300

* Author: Santiago Pastorino
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.3.0dev (2015-03-01 trunk 49796) [x86_64-darwin14]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
The following code ...

```ruby
class Y
  def initialize
    @x = "ZOMG"
  end

  def print_x
    puts x
  end

  private

  attr_reader :x
end

Y.new.print_x
```

outputs ...

```
test.rb:12: warning: private attribute?
```

I tend to think this warning is wrong, I was surprised by https://github.com/rack/rack/pull/811 and I think this is a completely valid use case.

Also this code ...

```ruby
class Y
  def initialize
    @x = "ZOMG"
  end

  def print_x
    puts x
  end

  def assign_x
    self.x = "ZOMG ZOMG"
  end

  private

  attr_accessor :x
end

y = Y.new
y.assign_x
y.print_x
```

Works fine with warnings also. So a private writer works ok when the receiver is `self` because Ruby has a special case for it, this make me think that private writers were thought to be used.

So ... am I wrong thinking that the warning should be removed or the self special case shouldn't work and be removed from Ruby code?. It doesn't make sense to me to have both things.



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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:69186] [Ruby trunk - Bug #10967] Is "warning: private attribute?" wrong?
       [not found] <redmine.issue-10967.20150311200640@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2015-04-30 18:23 ` [ruby-core:69042] " santiago
@ 2015-05-14  7:00 ` matz
  2015-06-30  4:18 ` [ruby-core:69804] " usa
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: matz @ 2015-05-14  7:00 UTC (permalink / raw)
  To: ruby-core

Issue #10967 has been updated by Yukihiro Matsumoto.


We haven't thought of self as a receiver. Agreed to remove warnings.

Matz.


----------------------------------------
Bug #10967: Is "warning: private attribute?" wrong?
https://bugs.ruby-lang.org/issues/10967#change-52443

* Author: Santiago Pastorino
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.3.0dev (2015-03-01 trunk 49796) [x86_64-darwin14]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
The following code ...

```ruby
class Y
  def initialize
    @x = "ZOMG"
  end

  def print_x
    puts x
  end

  private

  attr_reader :x
end

Y.new.print_x
```

outputs ...

```
test.rb:12: warning: private attribute?
```

I tend to think this warning is wrong, I was surprised by https://github.com/rack/rack/pull/811 and I think this is a completely valid use case.

Also this code ...

```ruby
class Y
  def initialize
    @x = "ZOMG"
  end

  def print_x
    puts x
  end

  def assign_x
    self.x = "ZOMG ZOMG"
  end

  private

  attr_accessor :x
end

y = Y.new
y.assign_x
y.print_x
```

Works fine with warnings also. So a private writer works ok when the receiver is `self` because Ruby has a special case for it, this make me think that private writers were thought to be used.

So ... am I wrong thinking that the warning should be removed or the self special case shouldn't work and be removed from Ruby code?. It doesn't make sense to me to have both things.



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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:69804] [Ruby trunk - Bug #10967] Is "warning: private attribute?" wrong?
       [not found] <redmine.issue-10967.20150311200640@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2015-05-14  7:00 ` [ruby-core:69186] " matz
@ 2015-06-30  4:18 ` usa
  2015-07-03  8:33 ` [ruby-core:69851] " usa
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: usa @ 2015-06-30  4:18 UTC (permalink / raw)
  To: ruby-core

Issue #10967 has been updated by Usaku NAKAMURA.

Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN to 2.0.0: WONTFIX, 2.1: REQUIRED, 2.2: REQUIRED

----------------------------------------
Bug #10967: Is "warning: private attribute?" wrong?
https://bugs.ruby-lang.org/issues/10967#change-53200

* Author: Santiago Pastorino
* Status: Closed
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.3.0dev (2015-03-01 trunk 49796) [x86_64-darwin14]
* Backport: 2.0.0: WONTFIX, 2.1: REQUIRED, 2.2: REQUIRED
----------------------------------------
The following code ...

```ruby
class Y
  def initialize
    @x = "ZOMG"
  end

  def print_x
    puts x
  end

  private

  attr_reader :x
end

Y.new.print_x
```

outputs ...

```
test.rb:12: warning: private attribute?
```

I tend to think this warning is wrong, I was surprised by https://github.com/rack/rack/pull/811 and I think this is a completely valid use case.

Also this code ...

```ruby
class Y
  def initialize
    @x = "ZOMG"
  end

  def print_x
    puts x
  end

  def assign_x
    self.x = "ZOMG ZOMG"
  end

  private

  attr_accessor :x
end

y = Y.new
y.assign_x
y.print_x
```

Works fine with warnings also. So a private writer works ok when the receiver is `self` because Ruby has a special case for it, this make me think that private writers were thought to be used.

So ... am I wrong thinking that the warning should be removed or the self special case shouldn't work and be removed from Ruby code?. It doesn't make sense to me to have both things.



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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:69851] [Ruby trunk - Bug #10967] Is "warning: private attribute?" wrong?
       [not found] <redmine.issue-10967.20150311200640@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2015-06-30  4:18 ` [ruby-core:69804] " usa
@ 2015-07-03  8:33 ` usa
  2015-08-14  6:45 ` [ruby-core:70383] " nagachika00
  2015-08-17  8:53 ` [ruby-core:70419] " usa
  9 siblings, 0 replies; 11+ messages in thread
From: usa @ 2015-07-03  8:33 UTC (permalink / raw)
  To: ruby-core

Issue #10967 has been updated by Usaku NAKAMURA.


Is this a spec change or a bug?

----------------------------------------
Bug #10967: Is "warning: private attribute?" wrong?
https://bugs.ruby-lang.org/issues/10967#change-53251

* Author: Santiago Pastorino
* Status: Closed
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.3.0dev (2015-03-01 trunk 49796) [x86_64-darwin14]
* Backport: 2.0.0: WONTFIX, 2.1: REQUIRED, 2.2: REQUIRED
----------------------------------------
The following code ...

```ruby
class Y
  def initialize
    @x = "ZOMG"
  end

  def print_x
    puts x
  end

  private

  attr_reader :x
end

Y.new.print_x
```

outputs ...

```
test.rb:12: warning: private attribute?
```

I tend to think this warning is wrong, I was surprised by https://github.com/rack/rack/pull/811 and I think this is a completely valid use case.

Also this code ...

```ruby
class Y
  def initialize
    @x = "ZOMG"
  end

  def print_x
    puts x
  end

  def assign_x
    self.x = "ZOMG ZOMG"
  end

  private

  attr_accessor :x
end

y = Y.new
y.assign_x
y.print_x
```

Works fine with warnings also. So a private writer works ok when the receiver is `self` because Ruby has a special case for it, this make me think that private writers were thought to be used.

So ... am I wrong thinking that the warning should be removed or the self special case shouldn't work and be removed from Ruby code?. It doesn't make sense to me to have both things.



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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:70383] [Ruby trunk - Bug #10967] Is "warning: private attribute?" wrong?
       [not found] <redmine.issue-10967.20150311200640@ruby-lang.org>
                   ` (7 preceding siblings ...)
  2015-07-03  8:33 ` [ruby-core:69851] " usa
@ 2015-08-14  6:45 ` nagachika00
  2015-08-17  8:53 ` [ruby-core:70419] " usa
  9 siblings, 0 replies; 11+ messages in thread
From: nagachika00 @ 2015-08-14  6:45 UTC (permalink / raw)
  To: ruby-core

Issue #10967 has been updated by Tomoyuki Chikanaga.

Backport changed from 2.0.0: WONTFIX, 2.1: REQUIRED, 2.2: REQUIRED to 2.0.0: WONTFIX, 2.1: REQUIRED, 2.2: WONTFIX

Hmm, I don't know it's a bug fix or a spec change, but I think it's a trivial issue. I decided to not to backport to 2.2. Please notice if any objections.

----------------------------------------
Bug #10967: Is "warning: private attribute?" wrong?
https://bugs.ruby-lang.org/issues/10967#change-53786

* Author: Santiago Pastorino
* Status: Closed
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.3.0dev (2015-03-01 trunk 49796) [x86_64-darwin14]
* Backport: 2.0.0: WONTFIX, 2.1: REQUIRED, 2.2: WONTFIX
----------------------------------------
The following code ...

```ruby
class Y
  def initialize
    @x = "ZOMG"
  end

  def print_x
    puts x
  end

  private

  attr_reader :x
end

Y.new.print_x
```

outputs ...

```
test.rb:12: warning: private attribute?
```

I tend to think this warning is wrong, I was surprised by https://github.com/rack/rack/pull/811 and I think this is a completely valid use case.

Also this code ...

```ruby
class Y
  def initialize
    @x = "ZOMG"
  end

  def print_x
    puts x
  end

  def assign_x
    self.x = "ZOMG ZOMG"
  end

  private

  attr_accessor :x
end

y = Y.new
y.assign_x
y.print_x
```

Works fine with warnings also. So a private writer works ok when the receiver is `self` because Ruby has a special case for it, this make me think that private writers were thought to be used.

So ... am I wrong thinking that the warning should be removed or the self special case shouldn't work and be removed from Ruby code?. It doesn't make sense to me to have both things.



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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:70419] [Ruby trunk - Bug #10967] Is "warning: private attribute?" wrong?
       [not found] <redmine.issue-10967.20150311200640@ruby-lang.org>
                   ` (8 preceding siblings ...)
  2015-08-14  6:45 ` [ruby-core:70383] " nagachika00
@ 2015-08-17  8:53 ` usa
  9 siblings, 0 replies; 11+ messages in thread
From: usa @ 2015-08-17  8:53 UTC (permalink / raw)
  To: ruby-core

Issue #10967 has been updated by Usaku NAKAMURA.

Backport changed from 2.0.0: WONTFIX, 2.1: REQUIRED, 2.2: WONTFIX to 2.0.0: WONTFIX, 2.1: WONTFIX, 2.2: WONTFIX

Ok, I follow you, chikanaga-san!

----------------------------------------
Bug #10967: Is "warning: private attribute?" wrong?
https://bugs.ruby-lang.org/issues/10967#change-53828

* Author: Santiago Pastorino
* Status: Closed
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.3.0dev (2015-03-01 trunk 49796) [x86_64-darwin14]
* Backport: 2.0.0: WONTFIX, 2.1: WONTFIX, 2.2: WONTFIX
----------------------------------------
The following code ...

```ruby
class Y
  def initialize
    @x = "ZOMG"
  end

  def print_x
    puts x
  end

  private

  attr_reader :x
end

Y.new.print_x
```

outputs ...

```
test.rb:12: warning: private attribute?
```

I tend to think this warning is wrong, I was surprised by https://github.com/rack/rack/pull/811 and I think this is a completely valid use case.

Also this code ...

```ruby
class Y
  def initialize
    @x = "ZOMG"
  end

  def print_x
    puts x
  end

  def assign_x
    self.x = "ZOMG ZOMG"
  end

  private

  attr_accessor :x
end

y = Y.new
y.assign_x
y.print_x
```

Works fine with warnings also. So a private writer works ok when the receiver is `self` because Ruby has a special case for it, this make me think that private writers were thought to be used.

So ... am I wrong thinking that the warning should be removed or the self special case shouldn't work and be removed from Ruby code?. It doesn't make sense to me to have both things.



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

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-08-17  8:18 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-10967.20150311200640@ruby-lang.org>
2015-03-11 20:06 ` [ruby-core:68502] [Ruby trunk - Bug #10967] [Open] Is "warning: private attribute?" wrong? santiago
2015-03-12 15:03 ` [ruby-core:68510] [Ruby trunk - Bug #10967] " santiago
2015-03-28  8:36   ` [ruby-core:68667] Re: [Ruby trunk - Bug #10967] [Open] " Zachary Scott
2015-04-27 22:42 ` [ruby-core:69005] [Ruby trunk - Bug #10967] " nobu
2015-04-28  0:25 ` [ruby-core:69007] " ruby-core
2015-04-30 18:23 ` [ruby-core:69042] " santiago
2015-05-14  7:00 ` [ruby-core:69186] " matz
2015-06-30  4:18 ` [ruby-core:69804] " usa
2015-07-03  8:33 ` [ruby-core:69851] " usa
2015-08-14  6:45 ` [ruby-core:70383] " nagachika00
2015-08-17  8:53 ` [ruby-core:70419] " usa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).