[ruby-core:96398] [Ruby master Feature#6810] `module A::B; end` is not equivalent to `module A; module B; end; end` with respect to constant lookup (scope)

[email protected]
Newsgroups gmane.comp.lang.ruby.core
Message-ID <redmine.journal-83322.20191222045508.4952a8ad4c6d5bc8@ruby-lang.org>
Issue #6810 has been updated by sawa (Tsuyoshi Sawada).


At lest as of Ruby 2.6.5, I get a different output from above for at least one of the examples:

```ruby
N = 0

module A
  module B
    def self.f; N; end
  end

  N = 1
end

N = 0

A::B.f # => 1
```

----------------------------------------
Feature #6810: `module A::B; end` is not equivalent to `module A; module B; end; end` with respect to constant lookup (scope)
https://bugs.ruby-lang.org/issues/6810#change-83322

* Author: alexeymuranov (Alexey Muranov)
* Status: Assigned
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 3.0
----------------------------------------
Is this the expected behavior? To me, it is rather surprising:

```ruby
N = 0

module A
  module B
    def self.f; N; end
  end

  N = 1
end

A::B.f # => 1

N = 0

A::B.f # => 0

A::N = 1

A::B.f # => 1

A::B::N = 2

A::B.f # => 2
```

but

```ruby
N = 0

module A; end

module A::B
  def self.f; N; end
end

module A
  N = 1
end

A::B.f # => 0

N = 0

A::B.f # => 0

A::N = 1

A::B.f # => 0

A::B::N = 2

A::B.f # => 2
```




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

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.