ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:79751] [Ruby trunk Bug#13249] Access modifiers don't have an effect inside class methods in Ruby >= 2.3
       [not found] <redmine.issue-13249.20170224191346@ruby-lang.org>
@ 2017-02-24 19:13 ` botalov.andrey
  2017-02-24 19:34 ` [ruby-core:79752] " botalov.andrey
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: botalov.andrey @ 2017-02-24 19:13 UTC (permalink / raw)
  To: ruby-core

Issue #13249 has been reported by Andrey Botalov.

----------------------------------------
Bug #13249: Access modifiers don't have an effect inside class methods in Ruby >= 2.3
https://bugs.ruby-lang.org/issues/13249

* Author: Andrey Botalov
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.3.0, 2.4.0
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
Simple example:
~~~ ruby
class C
  def self.foo
    private
    def bar
    end
  end
end
C.foo
C.new.bar
~~~

This code runs fine on Ruby 2.3 and Ruby 2.4. It raises NoMethodError on Ruby 2.2 and prior versions.
I would expect an error to be raised.

Here is some code that actually uses private access modifier inside a class method - https://github.com/evolve75/RubyTree/blob/db48c35b0a3b96e4da473b095cc00e454d8a9996/lib/tree/utils/camel_case_method_handler.rb#L60

By the way, this code raises an error as expected on Ruby 2.3 and Ruby 2.4:
~~~ ruby
class C
  def self.foo
    private def bar
    end
  end
end
C.foo
C.new.bar
~~~




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

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

* [ruby-core:79752] [Ruby trunk Bug#13249] Access modifiers don't have an effect inside class methods in Ruby >= 2.3
       [not found] <redmine.issue-13249.20170224191346@ruby-lang.org>
  2017-02-24 19:13 ` [ruby-core:79751] [Ruby trunk Bug#13249] Access modifiers don't have an effect inside class methods in Ruby >= 2.3 botalov.andrey
@ 2017-02-24 19:34 ` botalov.andrey
  2017-02-24 19:35 ` [ruby-core:79753] " botalov.andrey
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: botalov.andrey @ 2017-02-24 19:34 UTC (permalink / raw)
  To: ruby-core

Issue #13249 has been updated by Andrei Botalov.

Description updated

----------------------------------------
Bug #13249: Access modifiers don't have an effect inside class methods in Ruby >= 2.3
https://bugs.ruby-lang.org/issues/13249#change-63176

* Author: Andrei Botalov
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.3.0, 2.4.0
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
Simple example:
~~~ ruby
class C
  def self.foo
    private
    def bar
    end
  end
end
C.foo
C.new.bar

~~~

This code runs fine on Ruby 2.3 and Ruby 2.4. It raises NoMethodError on Ruby 2.2 and prior versions.
I would expect an error to be raised.

Here is some code that actually uses private access modifier inside a class method - https://github.com/evolve75/RubyTree/blob/db48c35b0a3b96e4da473b095cc00e454d8a9996/lib/tree/utils/camel_case_method_handler.rb#L60

By the way, this code raises an error as expected on Ruby 2.3 and Ruby 2.4:
~~~ ruby
class C
  def self.foo
    private def bar
    end
  end
end
C.foo
C.new.bar

~~~




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

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

* [ruby-core:79753] [Ruby trunk Bug#13249] Access modifiers don't have an effect inside class methods in Ruby >= 2.3
       [not found] <redmine.issue-13249.20170224191346@ruby-lang.org>
  2017-02-24 19:13 ` [ruby-core:79751] [Ruby trunk Bug#13249] Access modifiers don't have an effect inside class methods in Ruby >= 2.3 botalov.andrey
  2017-02-24 19:34 ` [ruby-core:79752] " botalov.andrey
@ 2017-02-24 19:35 ` botalov.andrey
  2017-02-24 23:20 ` [ruby-core:79758] " nobu
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: botalov.andrey @ 2017-02-24 19:35 UTC (permalink / raw)
  To: ruby-core

Issue #13249 has been updated by Andrei Botalov.

Description updated

----------------------------------------
Bug #13249: Access modifiers don't have an effect inside class methods in Ruby >= 2.3
https://bugs.ruby-lang.org/issues/13249#change-63177

* Author: Andrei Botalov
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.3.0, 2.4.0
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
Simple example:

~~~ ruby
class C
  def self.foo
    private
    def bar
    end
  end
end
C.foo
C.new.bar
~~~

This code runs fine on Ruby 2.3 and Ruby 2.4. It raises NoMethodError on Ruby 2.2 and prior versions.
I would expect an error to be raised.

Here is some code that actually uses private access modifier inside a class method - https://github.com/evolve75/RubyTree/blob/db48c35b0a3b96e4da473b095cc00e454d8a9996/lib/tree/utils/camel_case_method_handler.rb#L60

By the way, this code raises an error as expected on Ruby 2.3 and Ruby 2.4:

~~~ ruby
class C
  def self.foo
    private def bar
    end
  end
end
C.foo
C.new.bar
~~~




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

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

* [ruby-core:79758] [Ruby trunk Bug#13249] Access modifiers don't have an effect inside class methods in Ruby >= 2.3
       [not found] <redmine.issue-13249.20170224191346@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2017-02-24 19:35 ` [ruby-core:79753] " botalov.andrey
@ 2017-02-24 23:20 ` nobu
  2017-02-25  7:11 ` [ruby-core:79770] " botalov.andrey
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: nobu @ 2017-02-24 23:20 UTC (permalink / raw)
  To: ruby-core

Issue #13249 has been updated by Nobuyoshi Nakada.


Hmmm, a class singleton method should have its own visibility per invocations?

----------------------------------------
Bug #13249: Access modifiers don't have an effect inside class methods in Ruby >= 2.3
https://bugs.ruby-lang.org/issues/13249#change-63185

* Author: Andrei Botalov
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.3.0, 2.4.0
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
Simple example:

~~~ ruby
class C
  def self.foo
    private
    def bar
    end
  end
end
C.foo
C.new.bar
~~~

This code runs fine on Ruby 2.3 and Ruby 2.4. It raises NoMethodError on Ruby 2.2 and prior versions.
I would expect an error to be raised.

Here is some code that actually uses private access modifier inside a class method - https://github.com/evolve75/RubyTree/blob/db48c35b0a3b96e4da473b095cc00e454d8a9996/lib/tree/utils/camel_case_method_handler.rb#L60

By the way, this code raises an error as expected on Ruby 2.3 and Ruby 2.4:

~~~ ruby
class C
  def self.foo
    private def bar
    end
  end
end
C.foo
C.new.bar
~~~




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

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

* [ruby-core:79770] [Ruby trunk Bug#13249] Access modifiers don't have an effect inside class methods in Ruby >= 2.3
       [not found] <redmine.issue-13249.20170224191346@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2017-02-24 23:20 ` [ruby-core:79758] " nobu
@ 2017-02-25  7:11 ` botalov.andrey
  2017-02-25 19:18 ` [ruby-core:79774] " shevegen
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: botalov.andrey @ 2017-02-25  7:11 UTC (permalink / raw)
  To: ruby-core

Issue #13249 has been updated by Andrei Botalov.


Well, ability to declare `private` methods inside class methods seems strange given that it's not possible to declare private methods inside instance methods:

~~~ ruby
class C
  def foo
    private def bar
    end
  end
end
C.new.foo # NoMethodError is raised
~~~

So I'm not sure which route would be better.

----------------------------------------
Bug #13249: Access modifiers don't have an effect inside class methods in Ruby >= 2.3
https://bugs.ruby-lang.org/issues/13249#change-63196

* Author: Andrei Botalov
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.3.0, 2.4.0
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
Simple example:

~~~ ruby
class C
  def self.foo
    private
    def bar
    end
  end
end
C.foo
C.new.bar
~~~

This code runs fine on Ruby 2.3 and Ruby 2.4. It raises NoMethodError on Ruby 2.2 and prior versions.
I would expect an error to be raised.

Here is some code that actually uses private access modifier inside a class method - https://github.com/evolve75/RubyTree/blob/db48c35b0a3b96e4da473b095cc00e454d8a9996/lib/tree/utils/camel_case_method_handler.rb#L60

By the way, this code raises an error as expected on Ruby 2.3 and Ruby 2.4:

~~~ ruby
class C
  def self.foo
    private def bar
    end
  end
end
C.foo
C.new.bar
~~~




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

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

* [ruby-core:79774] [Ruby trunk Bug#13249] Access modifiers don't have an effect inside class methods in Ruby >= 2.3
       [not found] <redmine.issue-13249.20170224191346@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2017-02-25  7:11 ` [ruby-core:79770] " botalov.andrey
@ 2017-02-25 19:18 ` shevegen
  2017-02-26 11:41 ` [ruby-core:79787] " botalov.andrey
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: shevegen @ 2017-02-25 19:18 UTC (permalink / raw)
  To: ruby-core

Issue #13249 has been updated by Robert A. Heiler.


The examples confuse me a bit.

Does private actually make sense on any class-method / singleton method?

I understand it as a limitation for methods on the class, where outside
calls are not allowed, only internal ones (though ruby allows one to
bypass these anyway via .send).

I am also confused by the second example:

  class C
    def self.foo
      private def bar
      end
    end
  end
  C.foo
  C.new.bar

Is that not equivalent to

  private
  def self.bar
?

So why would this work on the C.new.bar() level?

It is however had interesting that this worked on 2.2 and below but
was changed past that point.

----------------------------------------
Bug #13249: Access modifiers don't have an effect inside class methods in Ruby >= 2.3
https://bugs.ruby-lang.org/issues/13249#change-63199

* Author: Andrei Botalov
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.3.0, 2.4.0
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
Simple example:

~~~ ruby
class C
  def self.foo
    private
    def bar
    end
  end
end
C.foo
C.new.bar
~~~

This code runs fine on Ruby 2.3 and Ruby 2.4. It raises NoMethodError on Ruby 2.2 and prior versions.
I would expect an error to be raised.

Here is some code that actually uses private access modifier inside a class method - https://github.com/evolve75/RubyTree/blob/db48c35b0a3b96e4da473b095cc00e454d8a9996/lib/tree/utils/camel_case_method_handler.rb#L60

By the way, this code raises an error as expected on Ruby 2.3 and Ruby 2.4:

~~~ ruby
class C
  def self.foo
    private def bar
    end
  end
end
C.foo
C.new.bar
~~~




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

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

* [ruby-core:79787] [Ruby trunk Bug#13249] Access modifiers don't have an effect inside class methods in Ruby >= 2.3
       [not found] <redmine.issue-13249.20170224191346@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2017-02-25 19:18 ` [ruby-core:79774] " shevegen
@ 2017-02-26 11:41 ` botalov.andrey
  2017-04-18  4:38 ` [ruby-core:80756] [Ruby trunk Bug#13249][Assigned] " shyouhei
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: botalov.andrey @ 2017-02-26 11:41 UTC (permalink / raw)
  To: ruby-core

Issue #13249 has been updated by Andrei Botalov.

Description updated

----------------------------------------
Bug #13249: Access modifiers don't have an effect inside class methods in Ruby >= 2.3
https://bugs.ruby-lang.org/issues/13249#change-63212

* Author: Andrei Botalov
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.3.0, 2.4.0
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
Simple example:

~~~ ruby
class C
  def self.foo
    private
    def bar
    end
  end
end
C.foo
C.new.bar
~~~

This code runs fine on Ruby 2.3 and Ruby 2.4. It raises NoMethodError on Ruby 2.2 and prior versions.
I would expect an error to be raised.

Here is some code that actually uses private access modifier inside a class method - https://github.com/evolve75/RubyTree/blob/db48c35b0a3b96e4da473b095cc00e454d8a9996/lib/tree/utils/camel_case_method_handler.rb#L60

By the way, this code raises an error as expected on Ruby 2.3 and Ruby 2.4:

~~~ ruby
class C
  def self.foo
    private def bar
    end
  end
end
C.foo
C.new.bar # NoMethodError: private method `bar' called
~~~




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

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

* [ruby-core:80756] [Ruby trunk Bug#13249][Assigned] Access modifiers don't have an effect inside class methods in Ruby >= 2.3
       [not found] <redmine.issue-13249.20170224191346@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2017-02-26 11:41 ` [ruby-core:79787] " botalov.andrey
@ 2017-04-18  4:38 ` shyouhei
  2017-05-19  7:34 ` [ruby-core:81261] [Ruby trunk Bug#13249] " ko1
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: shyouhei @ 2017-04-18  4:38 UTC (permalink / raw)
  To: ruby-core

Issue #13249 has been updated by shyouhei (Shyouhei Urabe).

Status changed from Open to Assigned
Assignee set to ko1 (Koichi Sasada)

We looked at this issue in yesterday's developer meeting.

The use of private in evolve75/RubyTree shown in the description is in fact wrong (methods are defined in a wrong place).  That example made us think that the use of private in a method is a code smell.

We would forbid such usage in a future.  For the time being, let us show warning message.

----------------------------------------
Bug #13249: Access modifiers don't have an effect inside class methods in Ruby >= 2.3
https://bugs.ruby-lang.org/issues/13249#change-64312

* Author: abotalov (Andrei Botalov)
* Status: Assigned
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Target version: 
* ruby -v: 2.3.0, 2.4.0
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
Simple example:

~~~ ruby
class C
  def self.foo
    private
    def bar
    end
  end
end
C.foo
C.new.bar
~~~

This code runs fine on Ruby 2.3 and Ruby 2.4. It raises NoMethodError on Ruby 2.2 and prior versions.
I would expect an error to be raised.

Here is some code that actually uses private access modifier inside a class method - https://github.com/evolve75/RubyTree/blob/db48c35b0a3b96e4da473b095cc00e454d8a9996/lib/tree/utils/camel_case_method_handler.rb#L60

By the way, this code raises an error as expected on Ruby 2.3 and Ruby 2.4:

~~~ ruby
class C
  def self.foo
    private def bar
    end
  end
end
C.foo
C.new.bar # NoMethodError: private method `bar' called
~~~




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

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

* [ruby-core:81261] [Ruby trunk Bug#13249] Access modifiers don't have an effect inside class methods in Ruby >= 2.3
       [not found] <redmine.issue-13249.20170224191346@ruby-lang.org>
                   ` (7 preceding siblings ...)
  2017-04-18  4:38 ` [ruby-core:80756] [Ruby trunk Bug#13249][Assigned] " shyouhei
@ 2017-05-19  7:34 ` ko1
  2019-08-25  0:23 ` [ruby-core:94539] [Ruby master " merch-redmine
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: ko1 @ 2017-05-19  7:34 UTC (permalink / raw)
  To: ruby-core

Issue #13249 has been updated by ko1 (Koichi Sasada).


I will insert warning.
I will not change the current behavior.


----------------------------------------
Bug #13249: Access modifiers don't have an effect inside class methods in Ruby >= 2.3
https://bugs.ruby-lang.org/issues/13249#change-64926

* Author: abotalov (Andrei Botalov)
* Status: Assigned
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Target version: 
* ruby -v: 2.3.0, 2.4.0
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
Simple example:

~~~ ruby
class C
  def self.foo
    private
    def bar
    end
  end
end
C.foo
C.new.bar
~~~

This code runs fine on Ruby 2.3 and Ruby 2.4. It raises NoMethodError on Ruby 2.2 and prior versions.
I would expect an error to be raised.

Here is some code that actually uses private access modifier inside a class method - https://github.com/evolve75/RubyTree/blob/db48c35b0a3b96e4da473b095cc00e454d8a9996/lib/tree/utils/camel_case_method_handler.rb#L60

By the way, this code raises an error as expected on Ruby 2.3 and Ruby 2.4:

~~~ ruby
class C
  def self.foo
    private def bar
    end
  end
end
C.foo
C.new.bar # NoMethodError: private method `bar' called
~~~




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

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

* [ruby-core:94539] [Ruby master Bug#13249] Access modifiers don't have an effect inside class methods in Ruby >= 2.3
       [not found] <redmine.issue-13249.20170224191346@ruby-lang.org>
                   ` (8 preceding siblings ...)
  2017-05-19  7:34 ` [ruby-core:81261] [Ruby trunk Bug#13249] " ko1
@ 2019-08-25  0:23 ` merch-redmine
  2019-10-16  5:26 ` [ruby-core:95351] " mame
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: merch-redmine @ 2019-08-25  0:23 UTC (permalink / raw)
  To: ruby-core

Issue #13249 has been updated by jeremyevans0 (Jeremy Evans).

File warn-scope-visibility-in-method-13249.patch added

The warning discussed has not been added yet.  Attached is a patch that implements it.  While it passes `make check`, there may be corner cases it doesn't handle.  I would appreciate review of the changes to `vm_cref_set_visibility`.

By adding this warning, I found a related issue in irb, which I submitted a pull request for: https://github.com/ruby/irb/pull/23

----------------------------------------
Bug #13249: Access modifiers don't have an effect inside class methods in Ruby >= 2.3
https://bugs.ruby-lang.org/issues/13249#change-80980

* Author: abotalov (Andrei Botalov)
* Status: Assigned
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Target version: 
* ruby -v: 2.3.0, 2.4.0
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
Simple example:

~~~ ruby
class C
  def self.foo
    private
    def bar
    end
  end
end
C.foo
C.new.bar
~~~

This code runs fine on Ruby 2.3 and Ruby 2.4. It raises NoMethodError on Ruby 2.2 and prior versions.
I would expect an error to be raised.

Here is some code that actually uses private access modifier inside a class method - https://github.com/evolve75/RubyTree/blob/db48c35b0a3b96e4da473b095cc00e454d8a9996/lib/tree/utils/camel_case_method_handler.rb#L60

By the way, this code raises an error as expected on Ruby 2.3 and Ruby 2.4:

~~~ ruby
class C
  def self.foo
    private def bar
    end
  end
end
C.foo
C.new.bar # NoMethodError: private method `bar' called
~~~


---Files--------------------------------
warn-scope-visibility-in-method-13249.patch (4.18 KB)


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

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

* [ruby-core:95351] [Ruby master Bug#13249] Access modifiers don't have an effect inside class methods in Ruby >= 2.3
       [not found] <redmine.issue-13249.20170224191346@ruby-lang.org>
                   ` (9 preceding siblings ...)
  2019-08-25  0:23 ` [ruby-core:94539] [Ruby master " merch-redmine
@ 2019-10-16  5:26 ` mame
  2019-10-16  7:06 ` [ruby-core:95356] " nobu
  2019-10-16 19:10 ` [ruby-core:95372] " merch-redmine
  12 siblings, 0 replies; 13+ messages in thread
From: mame @ 2019-10-16  5:26 UTC (permalink / raw)
  To: ruby-core

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

Assignee changed from ko1 (Koichi Sasada) to nobu (Nobuyoshi Nakada)

@nobu Could you review the patch?

----------------------------------------
Bug #13249: Access modifiers don't have an effect inside class methods in Ruby >= 2.3
https://bugs.ruby-lang.org/issues/13249#change-82059

* Author: abotalov (Andrei Botalov)
* Status: Assigned
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
* Target version: 
* ruby -v: 2.3.0, 2.4.0
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
Simple example:

~~~ ruby
class C
  def self.foo
    private
    def bar
    end
  end
end
C.foo
C.new.bar
~~~

This code runs fine on Ruby 2.3 and Ruby 2.4. It raises NoMethodError on Ruby 2.2 and prior versions.
I would expect an error to be raised.

Here is some code that actually uses private access modifier inside a class method - https://github.com/evolve75/RubyTree/blob/db48c35b0a3b96e4da473b095cc00e454d8a9996/lib/tree/utils/camel_case_method_handler.rb#L60

By the way, this code raises an error as expected on Ruby 2.3 and Ruby 2.4:

~~~ ruby
class C
  def self.foo
    private def bar
    end
  end
end
C.foo
C.new.bar # NoMethodError: private method `bar' called
~~~


---Files--------------------------------
warn-scope-visibility-in-method-13249.patch (4.18 KB)


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

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

* [ruby-core:95356] [Ruby master Bug#13249] Access modifiers don't have an effect inside class methods in Ruby >= 2.3
       [not found] <redmine.issue-13249.20170224191346@ruby-lang.org>
                   ` (10 preceding siblings ...)
  2019-10-16  5:26 ` [ruby-core:95351] " mame
@ 2019-10-16  7:06 ` nobu
  2019-10-16 19:10 ` [ruby-core:95372] " merch-redmine
  12 siblings, 0 replies; 13+ messages in thread
From: nobu @ 2019-10-16  7:06 UTC (permalink / raw)
  To: ruby-core

Issue #13249 has been updated by nobu (Nobuyoshi Nakada).


* Is it necessary that check is placed inside the function `vm_cref_set_visibility`?
  What about calling a separate function where `check_method` flag is 1?

* `rb_frame_callee` returns the called name, that may be an aliased name.
  Is it intentional?

----------------------------------------
Bug #13249: Access modifiers don't have an effect inside class methods in Ruby >= 2.3
https://bugs.ruby-lang.org/issues/13249#change-82064

* Author: abotalov (Andrei Botalov)
* Status: Assigned
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
* Target version: 
* ruby -v: 2.3.0, 2.4.0
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
Simple example:

~~~ ruby
class C
  def self.foo
    private
    def bar
    end
  end
end
C.foo
C.new.bar
~~~

This code runs fine on Ruby 2.3 and Ruby 2.4. It raises NoMethodError on Ruby 2.2 and prior versions.
I would expect an error to be raised.

Here is some code that actually uses private access modifier inside a class method - https://github.com/evolve75/RubyTree/blob/db48c35b0a3b96e4da473b095cc00e454d8a9996/lib/tree/utils/camel_case_method_handler.rb#L60

By the way, this code raises an error as expected on Ruby 2.3 and Ruby 2.4:

~~~ ruby
class C
  def self.foo
    private def bar
    end
  end
end
C.foo
C.new.bar # NoMethodError: private method `bar' called
~~~


---Files--------------------------------
warn-scope-visibility-in-method-13249.patch (4.18 KB)


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

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

* [ruby-core:95372] [Ruby master Bug#13249] Access modifiers don't have an effect inside class methods in Ruby >= 2.3
       [not found] <redmine.issue-13249.20170224191346@ruby-lang.org>
                   ` (11 preceding siblings ...)
  2019-10-16  7:06 ` [ruby-core:95356] " nobu
@ 2019-10-16 19:10 ` merch-redmine
  12 siblings, 0 replies; 13+ messages in thread
From: merch-redmine @ 2019-10-16 19:10 UTC (permalink / raw)
  To: ruby-core

Issue #13249 has been updated by jeremyevans0 (Jeremy Evans).


nobu (Nobuyoshi Nakada) wrote:
> * Is it necessary that check is placed inside the function `vm_cref_set_visibility`?
>   What about calling a separate function where `check_method` flag is 1?

I agree, that makes more sense.

> * `rb_frame_callee` returns the called name, that may be an aliased name.
>   Is it intentional?

No.  It would be better to use `rb_frame_this_func` instead, I think.

Thank you very much for your review. I've added the modified patch as a pull request (https://github.com/ruby/ruby/pull/2562).  Assuming it passes CI, I will merge it.

----------------------------------------
Bug #13249: Access modifiers don't have an effect inside class methods in Ruby >= 2.3
https://bugs.ruby-lang.org/issues/13249#change-82080

* Author: abotalov (Andrei Botalov)
* Status: Assigned
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
* Target version: 
* ruby -v: 2.3.0, 2.4.0
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
Simple example:

~~~ ruby
class C
  def self.foo
    private
    def bar
    end
  end
end
C.foo
C.new.bar
~~~

This code runs fine on Ruby 2.3 and Ruby 2.4. It raises NoMethodError on Ruby 2.2 and prior versions.
I would expect an error to be raised.

Here is some code that actually uses private access modifier inside a class method - https://github.com/evolve75/RubyTree/blob/db48c35b0a3b96e4da473b095cc00e454d8a9996/lib/tree/utils/camel_case_method_handler.rb#L60

By the way, this code raises an error as expected on Ruby 2.3 and Ruby 2.4:

~~~ ruby
class C
  def self.foo
    private def bar
    end
  end
end
C.foo
C.new.bar # NoMethodError: private method `bar' called
~~~


---Files--------------------------------
warn-scope-visibility-in-method-13249.patch (4.18 KB)


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

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

end of thread, other threads:[~2019-10-16 19:10 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-13249.20170224191346@ruby-lang.org>
2017-02-24 19:13 ` [ruby-core:79751] [Ruby trunk Bug#13249] Access modifiers don't have an effect inside class methods in Ruby >= 2.3 botalov.andrey
2017-02-24 19:34 ` [ruby-core:79752] " botalov.andrey
2017-02-24 19:35 ` [ruby-core:79753] " botalov.andrey
2017-02-24 23:20 ` [ruby-core:79758] " nobu
2017-02-25  7:11 ` [ruby-core:79770] " botalov.andrey
2017-02-25 19:18 ` [ruby-core:79774] " shevegen
2017-02-26 11:41 ` [ruby-core:79787] " botalov.andrey
2017-04-18  4:38 ` [ruby-core:80756] [Ruby trunk Bug#13249][Assigned] " shyouhei
2017-05-19  7:34 ` [ruby-core:81261] [Ruby trunk Bug#13249] " ko1
2019-08-25  0:23 ` [ruby-core:94539] [Ruby master " merch-redmine
2019-10-16  5:26 ` [ruby-core:95351] " mame
2019-10-16  7:06 ` [ruby-core:95356] " nobu
2019-10-16 19:10 ` [ruby-core:95372] " merch-redmine

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