Bug #5657
closedConstants in included modules aren't visible when defining classes with Class.new
Description
I define two classes that include a module. One is defined with class
, one is defined with Class.new
. I expect both to be able to reference constants in the included module. The class
one can, but the Class.new
one can't. Reproducing code:
module X
module Y
end
end
class Class1
include X
def self.f
# Works: Y is printed
p Y
end
end
Class2 = Class.new do
include X
def self.f
# Fails: "uninitialized constant Y"
p Y
end
end
Class1.f
Class2.f
It works with 1.9.2:
$ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]
$ ruby bug.rb
X::Y
X::Y
but not 1.9.3-p0:
$ ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10.8.0]
$ ruby bug.rb
X::Y
bug.rb:18:in f': uninitialized constant Y (NameError) from bug.rb:23:in
'
or 1.9.3-head:
$ ruby -v
ruby 1.9.3p0 (2011-11-08) [x86_64-darwin10.8.0]
$ ruby bug.rb
X::Y
bug.rb:18:in f': uninitialized constant Y (NameError) from bug.rb:23:in
'
I discovered this because it RSpec specs when going to 1.9.3: https://github.com/rspec/rspec-core/issues/506
Updated by shugo (Shugo Maeda) about 13 years ago
- ruby -v changed from ruby 1.9.3p0 (2011-11-08) [x86_64-darwin10.8.0] to -
It was a bug of 1.9.2 and fixed in 1.9.3.
http://redmine.ruby-lang.org/issues/4536 (in Japanese)
Constants should be lookuped statically.
The behaviour is the same as 1.8.
2011/11/22 11:37 "Gary Bernhardt" gary.bernhardt@gmail.com:
Issue #5657 has been reported by Gary Bernhardt.
Bug #5657: Constants in included modules aren't visible when defining
classes with Class.new
http://redmine.ruby-lang.org/issues/5657Author: Gary Bernhardt
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 1.9.3p0 (2011-11-08) [x86_64-darwin10.8.0]I define two classes that include a module. One is defined with
class
,
one is defined withClass.new
. I expect both to be able to reference
constants in the included module. Theclass
one can, but theClass.new
one can't. Reproducing code:module X
module Y
end
endclass Class1
include X
def self.fWorks: Y is printed¶
p Y
end
endClass2 = Class.new do
include X
def self.fFails: "uninitialized constant Y"¶
p Y
end
endClass1.f
Class2.fIt works with 1.9.2:
$ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]
$ ruby bug.rb
X::Y
X::Ybut not 1.9.3-p0:
$ ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10.8.0]
$ ruby bug.rb
X::Y
bug.rb:18:inf': uninitialized constant Y (NameError) from bug.rb:23:in
'or 1.9.3-head:
$ ruby -v
ruby 1.9.3p0 (2011-11-08) [x86_64-darwin10.8.0]
$ ruby bug.rb
X::Y
bug.rb:18:inf': uninitialized constant Y (NameError) from bug.rb:23:in
'I discovered this because it RSpec specs when going to 1.9.3:
https://github.com/rspec/rspec-core/issues/506
Updated by wycats (Yehuda Katz) about 13 years ago
Agreed. This was a bug in 1.9.2 probably caused by the (aborted) attempt to
change constant lookup rules in 1.9.
Yehuda Katz
(ph) 718.877.1325
On Mon, Nov 21, 2011 at 8:59 PM, Shugo Maeda shugo@ruby-lang.org wrote:
It was a bug of 1.9.2 and fixed in 1.9.3.
http://redmine.ruby-lang.org/issues/4536 (in Japanese)
Constants should be lookuped statically.
The behaviour is the same as 1.8.2011/11/22 11:37 "Gary Bernhardt" gary.bernhardt@gmail.com:
Issue #5657 has been reported by Gary Bernhardt.
Bug #5657: Constants in included modules aren't visible when defining
classes with Class.new
http://redmine.ruby-lang.org/issues/5657Author: Gary Bernhardt
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 1.9.3p0 (2011-11-08) [x86_64-darwin10.8.0]I define two classes that include a module. One is defined with
class
,
one is defined withClass.new
. I expect both to be able to reference
constants in the included module. Theclass
one can, but theClass.new
one can't. Reproducing code:module X
module Y
end
endclass Class1
include X
def self.fWorks: Y is printed¶
p Y
end
endClass2 = Class.new do
include X
def self.fFails: "uninitialized constant Y"¶
p Y
end
endClass1.f
Class2.fIt works with 1.9.2:
$ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]
$ ruby bug.rb
X::Y
X::Ybut not 1.9.3-p0:
$ ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10.8.0]
$ ruby bug.rb
X::Y
bug.rb:18:inf': uninitialized constant Y (NameError) from bug.rb:23:in
'or 1.9.3-head:
$ ruby -v
ruby 1.9.3p0 (2011-11-08) [x86_64-darwin10.8.0]
$ ruby bug.rb
X::Y
bug.rb:18:inf': uninitialized constant Y (NameError) from bug.rb:23:in
'I discovered this because it RSpec specs when going to 1.9.3:
https://github.com/rspec/rspec-core/issues/506
Updated by Anonymous about 13 years ago
In that case, I think that this can be safely closed.
Updated by shugo (Shugo Maeda) about 13 years ago
- Status changed from Open to Rejected
- Assignee set to shugo (Shugo Maeda)
Gary Bernhardt wrote:
In that case, I think that this can be safely closed.
Thanks for your confirmation.