Project

General

Profile

Bug #11754

Visibility scope is kept after lexical scope is closed

Added by printercu (Max Melentiev) over 3 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 2.3.0preview1 (2015-11-11 trunk 52539) [x86_64-darwin13]
[ruby-core:71762]

Description

module X
  def self.test_def
   def x; end; 
  end

  private
  def y; end; 
end
X.test_def
X.instance_methods

In 2.2 it returns [:x], in 2.3-preview1 it returns empty array. Is it ok?


Related issues

Related to Ruby master - Feature #11665: Support nested functions for better code organizationOpenActions
Related to Ruby master - Bug #13249: Access modifiers don't have an effect inside class methods in Ruby >= 2.3AssignedActions

Associated revisions

Revision 303cd88d
Added by ko1 (Koichi Sasada) over 3 years ago

  • vm.c (rb_vm_cref_in_context): Module#define_method in non-class
    expression should be public.
    [Bug #11754]

  • test/ruby/test_method.rb: add a test.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52996 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 52996
Added by ko1 (Koichi Sasada) over 3 years ago

  • vm.c (rb_vm_cref_in_context): Module#define_method in non-class
    expression should be public.
    [Bug #11754]

  • test/ruby/test_method.rb: add a test.

Revision 52996
Added by ko1 (Koichi Sasada) over 3 years ago

  • vm.c (rb_vm_cref_in_context): Module#define_method in non-class
    expression should be public.
    [Bug #11754]

  • test/ruby/test_method.rb: add a test.

Revision 52996
Added by ko1 (Koichi Sasada) over 3 years ago

  • vm.c (rb_vm_cref_in_context): Module#define_method in non-class
    expression should be public.
    [Bug #11754]

  • test/ruby/test_method.rb: add a test.

Revision 52996
Added by ko1 (Koichi Sasada) over 3 years ago

  • vm.c (rb_vm_cref_in_context): Module#define_method in non-class
    expression should be public.
    [Bug #11754]

  • test/ruby/test_method.rb: add a test.

Revision 52996
Added by ko1 (Koichi Sasada) over 3 years ago

  • vm.c (rb_vm_cref_in_context): Module#define_method in non-class
    expression should be public.
    [Bug #11754]

  • test/ruby/test_method.rb: add a test.

History

Updated by printercu (Max Melentiev) over 3 years ago

Better example

module X
  def self.test_def(name)
    define_method(name) {}
  end

  test_def :x

  private

  test_def :y 

  def pr; end
end

X.test_def :z
X.public_instance_methods
# 2.2.2 => [:x, :y, :z]
# 2.3-preview1 => [:x]

Updated by j15e (Jean-Philippe Doyle) over 3 years ago

  • ruby -v set to ruby 2.3.0preview1 (2015-11-11 trunk 52539) [x86_64-darwin13]

To provide some context, this creates issues with two gems I am using that have dynamically defined methods (that now seems to be incorrectly private in 2.3.0preview1) :

#3

Updated by mame (Yusuke Endoh) over 3 years ago

  • Related to Feature #11665: Support nested functions for better code organization added

Updated by ko1 (Koichi Sasada) over 3 years ago

  • Assignee set to ko1 (Koichi Sasada)
#5

Updated by ko1 (Koichi Sasada) over 3 years ago

  • Status changed from Open to Closed

Applied in changeset r52996.


  • vm.c (rb_vm_cref_in_context): Module#define_method in non-class
    expression should be public.
    [Bug #11754]

  • test/ruby/test_method.rb: add a test.

#6

Updated by nobu (Nobuyoshi Nakada) over 2 years ago

  • Related to Bug #13249: Access modifiers don't have an effect inside class methods in Ruby >= 2.3 added

Also available in: Atom PDF