ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:94511] [Ruby master Feature#16123] Allow calling a private method with `self.`
       [not found] <redmine.issue-16123.20190823210332@ruby-lang.org>
@ 2019-08-23 21:03 ` dylan.smith
  2019-08-23 23:06 ` [ruby-core:94515] " shevegen
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: dylan.smith @ 2019-08-23 21:03 UTC (permalink / raw)
  To: ruby-core

Issue #16123 has been reported by dylants (Dylan Thacker-Smith).

----------------------------------------
Feature #16123: Allow calling a private method with `self.`
https://bugs.ruby-lang.org/issues/16123

* Author: dylants (Dylan Thacker-Smith)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
## Problem

There is an inconsistency between calling a private attribute writer being allowed with `self.value =` syntax and `self.value` not being allowed on a private attribute writer.

Calling a private method in this way can be useful when trying to assign the return value of this private method to a local variable with the same name.

## Solution

The attached patch handles this by compiling the calling into a function call by using the `VM_CALL_FCALL` flag, so it is as if the call were made without the `self.` prefix, except it won't be confused with local variables at the VM instruction level.  It is also compiled like an assignment call, except I didn't use the `COMPILE_RECV` macro, since that would remove the `CHECK` macro usage around the `COMPILE` line.

---Files--------------------------------
0001-Allow-calling-a-private-method-with-self.diff.txt (3.28 KB)


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

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

* [ruby-core:94515] [Ruby master Feature#16123] Allow calling a private method with `self.`
       [not found] <redmine.issue-16123.20190823210332@ruby-lang.org>
  2019-08-23 21:03 ` [ruby-core:94511] [Ruby master Feature#16123] Allow calling a private method with `self.` dylan.smith
@ 2019-08-23 23:06 ` shevegen
  2019-08-24  0:30 ` [ruby-core:94518] " dylan.smith
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: shevegen @ 2019-08-23 23:06 UTC (permalink / raw)
  To: ruby-core

Issue #16123 has been updated by shevegen (Robert A. Heiler).


I may not completely understand the issue description. What is the inconsistency? (That is a honest
question, by the way; I am not fully understanding the issue domain.)

I am not even entirely sure what a private attribute writer is either; can we use these terms when
we can use e. g. send() at all times? I may not understand this, but I assume you can get the value
of any method via .send() and assign it to the local variable?

----------------------------------------
Feature #16123: Allow calling a private method with `self.`
https://bugs.ruby-lang.org/issues/16123#change-80951

* Author: dylants (Dylan Thacker-Smith)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
## Problem

There is an inconsistency between calling a private attribute writer being allowed with `self.value =` syntax and `self.value` not being allowed on a private attribute writer.

Calling a private method in this way can be useful when trying to assign the return value of this private method to a local variable with the same name.

## Solution

The attached patch handles this by compiling the calling into a function call by using the `VM_CALL_FCALL` flag, so it is as if the call were made without the `self.` prefix, except it won't be confused with local variables at the VM instruction level.  It is also compiled like an assignment call, except I didn't use the `COMPILE_RECV` macro, since that would remove the `CHECK` macro usage around the `COMPILE` line.

---Files--------------------------------
0001-Allow-calling-a-private-method-with-self.diff.txt (3.28 KB)


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

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

* [ruby-core:94518] [Ruby master Feature#16123] Allow calling a private method with `self.`
       [not found] <redmine.issue-16123.20190823210332@ruby-lang.org>
  2019-08-23 21:03 ` [ruby-core:94511] [Ruby master Feature#16123] Allow calling a private method with `self.` dylan.smith
  2019-08-23 23:06 ` [ruby-core:94515] " shevegen
@ 2019-08-24  0:30 ` dylan.smith
  2019-08-24  2:54 ` [ruby-core:94521] " sawadatsuyoshi
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 6+ messages in thread
From: dylan.smith @ 2019-08-24  0:30 UTC (permalink / raw)
  To: ruby-core

Issue #16123 has been updated by dylants (Dylan Thacker-Smith).


Here is a script to help demonstrate the inconsistency, where `self.bar = 123` is allowed by `self.bar` is not.

```ruby
class Foo
  def foo
    self.bar = 123 # allowed
    self.bar # raises
  end

  private

  attr_accessor :bar
end

Foo.new.foo
```

By attribute writer, I was just referring to an assignment method like the one defined by `attr_writer`, although the same applies to any assignment method like `def bar=(value); value; end`.  The inconsistency is just more obvious when dealing with the pair of methods defined by `attr_accessor` if they are private because `self.` works with one of them but not the other as shown above.

shevegen (Robert A. Heiler) wrote:
> I may not understand this, but I assume you can get the value of any method via .send() and assign it to the local variable?

Yes, it can be easily worked around, it just doesn't seem like it should be necessary to workaround this limitation.  The point of `private` is to keep things from being accessible from other objects, which we know isn't the case when a call is made on `self.` directly.

----------------------------------------
Feature #16123: Allow calling a private method with `self.`
https://bugs.ruby-lang.org/issues/16123#change-80954

* Author: dylants (Dylan Thacker-Smith)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
## Problem

There is an inconsistency between calling a private attribute writer being allowed with `self.value =` syntax and `self.value` not being allowed on a private attribute writer.

Calling a private method in this way can be useful when trying to assign the return value of this private method to a local variable with the same name.

## Solution

The attached patch handles this by compiling the calling into a function call by using the `VM_CALL_FCALL` flag, so it is as if the call were made without the `self.` prefix, except it won't be confused with local variables at the VM instruction level.  It is also compiled like an assignment call, except I didn't use the `COMPILE_RECV` macro, since that would remove the `CHECK` macro usage around the `COMPILE` line.

---Files--------------------------------
0001-Allow-calling-a-private-method-with-self.diff.txt (3.28 KB)


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

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

* [ruby-core:94521] [Ruby master Feature#16123] Allow calling a private method with `self.`
       [not found] <redmine.issue-16123.20190823210332@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2019-08-24  0:30 ` [ruby-core:94518] " dylan.smith
@ 2019-08-24  2:54 ` sawadatsuyoshi
  2019-09-18  8:01 ` [ruby-core:94953] " mame
  2019-09-19  8:17 ` [ruby-core:94982] " matz
  5 siblings, 0 replies; 6+ messages in thread
From: sawadatsuyoshi @ 2019-08-24  2:54 UTC (permalink / raw)
  To: ruby-core

Issue #16123 has been updated by sawa (Tsuyoshi Sawada).


The code you presented does not set the attribute methods private. The `attr_accessor` returns `nil`. Your `private` is applied to nothng.

----------------------------------------
Feature #16123: Allow calling a private method with `self.`
https://bugs.ruby-lang.org/issues/16123#change-80962

* Author: dylants (Dylan Thacker-Smith)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
## Problem

There is an inconsistency between calling a private attribute writer being allowed with `self.value =` syntax and `self.value` not being allowed on a private attribute writer.

Calling a private method in this way can be useful when trying to assign the return value of this private method to a local variable with the same name.

## Solution

The attached patch handles this by compiling the calling into a function call by using the `VM_CALL_FCALL` flag, so it is as if the call were made without the `self.` prefix, except it won't be confused with local variables at the VM instruction level.  It is also compiled like an assignment call, except I didn't use the `COMPILE_RECV` macro, since that would remove the `CHECK` macro usage around the `COMPILE` line.

---Files--------------------------------
0001-Allow-calling-a-private-method-with-self.diff.txt (3.28 KB)


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

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

* [ruby-core:94953] [Ruby master Feature#16123] Allow calling a private method with `self.`
       [not found] <redmine.issue-16123.20190823210332@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2019-08-24  2:54 ` [ruby-core:94521] " sawadatsuyoshi
@ 2019-09-18  8:01 ` mame
  2019-09-19  8:17 ` [ruby-core:94982] " matz
  5 siblings, 0 replies; 6+ messages in thread
From: mame @ 2019-09-18  8:01 UTC (permalink / raw)
  To: ruby-core

Issue #16123 has been updated by mame (Yusuke Endoh).


Why do you use private attr_accessor?  You can access its instance variable directly.

Allowing `self.private_method` has a unpreferable side effect; it allows `self.global_function`, i.e., `self.require "foo"`, `self.lambda { }`, `self.fork`, etc.

----------------------------------------
Feature #16123: Allow calling a private method with `self.`
https://bugs.ruby-lang.org/issues/16123#change-81569

* Author: dylants (Dylan Thacker-Smith)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
## Problem

There is an inconsistency between calling a private attribute writer being allowed with `self.value =` syntax and `self.value` not being allowed on a private attribute writer.

Calling a private method in this way can be useful when trying to assign the return value of this private method to a local variable with the same name.

## Solution

The attached patch handles this by compiling the calling into a function call by using the `VM_CALL_FCALL` flag, so it is as if the call were made without the `self.` prefix, except it won't be confused with local variables at the VM instruction level.  It is also compiled like an assignment call, except I didn't use the `COMPILE_RECV` macro, since that would remove the `CHECK` macro usage around the `COMPILE` line.

---Files--------------------------------
0001-Allow-calling-a-private-method-with-self.diff.txt (3.28 KB)


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

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

* [ruby-core:94982] [Ruby master Feature#16123] Allow calling a private method with `self.`
       [not found] <redmine.issue-16123.20190823210332@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2019-09-18  8:01 ` [ruby-core:94953] " mame
@ 2019-09-19  8:17 ` matz
  5 siblings, 0 replies; 6+ messages in thread
From: matz @ 2019-09-19  8:17 UTC (permalink / raw)
  To: ruby-core

Issue #16123 has been updated by matz (Yukihiro Matsumoto).


Accepted. But as I said in #11297, the document should be updated. After the patch, you can say `self.puts("hello")`, which can confuse you.

Matz.


----------------------------------------
Feature #16123: Allow calling a private method with `self.`
https://bugs.ruby-lang.org/issues/16123#change-81601

* Author: dylants (Dylan Thacker-Smith)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
## Problem

There is an inconsistency between calling a private attribute writer being allowed with `self.value =` syntax and `self.value` not being allowed on a private attribute writer.

Calling a private method in this way can be useful when trying to assign the return value of this private method to a local variable with the same name.

## Solution

The attached patch handles this by compiling the calling into a function call by using the `VM_CALL_FCALL` flag, so it is as if the call were made without the `self.` prefix, except it won't be confused with local variables at the VM instruction level.  It is also compiled like an assignment call, except I didn't use the `COMPILE_RECV` macro, since that would remove the `CHECK` macro usage around the `COMPILE` line.

---Files--------------------------------
0001-Allow-calling-a-private-method-with-self.diff.txt (3.28 KB)


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

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

end of thread, other threads:[~2019-09-19  8:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-16123.20190823210332@ruby-lang.org>
2019-08-23 21:03 ` [ruby-core:94511] [Ruby master Feature#16123] Allow calling a private method with `self.` dylan.smith
2019-08-23 23:06 ` [ruby-core:94515] " shevegen
2019-08-24  0:30 ` [ruby-core:94518] " dylan.smith
2019-08-24  2:54 ` [ruby-core:94521] " sawadatsuyoshi
2019-09-18  8:01 ` [ruby-core:94953] " mame
2019-09-19  8:17 ` [ruby-core:94982] " matz

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).