--485b397dd56d45557c04b24bc3ef
Content-Type: text/plain; charset=ISO-8859-1

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/5657
> >
> > Author: 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 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  lass.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 `<main>'
> >
> > 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 `<main>'
> >
> > I discovered this because it RSpec specs when going to 1.9.3:
> https://github.com/rspec/rspec-core/issues/506
> >
> >
> > --
> > http://redmine.ruby-lang.org
> >
>
>

--485b397dd56d45557c04b24bc3ef
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Agreed. This was a bug in 1.9.2 probably caused by the (aborted) attempt tohange constant lookup rules in 1.9.<div><br clear="all">Yehuda Katz<br>(ph) 718.877.1325<br>
<br><br><div class="gmail_quote">On Mon, Nov 21, 2011 at 8:59 PM, Shugo Maeda <span dir="ltr">&lt;shugo / ruby-lang.org&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<p>It was a bug of 1.9.2 and fixed in 1.9.3.</p>
<p><a href="http://redmine.ruby-lang.org/issues/4536" target="_blank">http://redmine.ruby-lang.org/issues/4536</a> (in Japanese)</p>
<p>Constants should be lookuped statically. <br>
The behaviour is the same as 1.8.</p>
<p>2011/11/22 11:37 &quot;Gary Bernhardt&quot; &lt;<a href="mailto:gary.bernhardt / gmail.com" target="_blank">gary.bernhardt / gmail.com</a>&gt;:</p><div><div class="h5"><br>
&gt;<br>
&gt;<br>
&gt; Issue #5657 has been reported by Gary Bernhardt.<br>
&gt;<br>
&gt; ----------------------------------------<br>
&gt; Bug #5657: Constants in included modules aren&#39;t visible when defining classes with Class.new<br>
&gt; <a href="http://redmine.ruby-lang.org/issues/5657" target="_blank">http://redmine.ruby-lang.org/issues/5657</a><br>
&gt;<br>
&gt; Author: Gary Bernhardt<br>
&gt; Status: Open<br>
&gt; Priority: Normal<br>
&gt; Assignee:<br>
&gt; Category:<br>
&gt; Target version:<br>
&gt; ruby -v: ruby 1.9.3p0 (2011-11-08) [x86_64-darwin10.8.0]<br>
&gt;<br>
&gt;<br>
&gt; 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&#39;t. Reproducing code:<br>



&gt;<br>
&gt; module X<br>
&gt;  ټ&gt;  
&gt; end<br>
&gt;<br>
&gt; class Class1<br>
&gt;   ؼ&gt;   
&gt;  Works: Y is printed<br>
&gt;   ټ&gt;  
&gt; end<br>
&gt;<br>
&gt; Class2 = Class.new do<br>
&gt;   ؼ&gt;   
&gt;  Fails: &quot;uninitialized constant Y&quot;<br>
&gt;   ټ&gt;  
&gt; end<br>
&gt;<br>
&gt; Class1.f<br>
&gt; Class2.f<br>
&gt;<br>
&gt; It works with 1.9.2:<br>
&gt;<br>
&gt; $ ruby -v<br>
&gt; ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]<br>
&gt; $ ruby bug.rb<br>
&gt; X::Y<br>
&gt; X::Y<br>
&gt;<br>
&gt; but not 1.9.3-p0:<br>
&gt;<br>
&gt; $ ruby -v<br>
&gt; ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10.8.0]<br>
&gt; $ ruby bug.rb<br>
&gt; X::Y<br>
&gt; bug.rb:18:in `f&#39;: uninitialized constant Y (NameError)<br>
&gt;  ⺲ 
&gt;<br>
&gt; or 1.9.3-head:<br>
&gt;<br>
&gt; $ ruby -v<br>
&gt; ruby 1.9.3p0 (2011-11-08) [x86_64-darwin10.8.0]<br>
&gt; $ ruby bug.rb<br>
&gt; X::Y<br>
&gt; bug.rb:18:in `f&#39;: uninitialized constant Y (NameError)<br>
&gt;  ⺲ 
&gt;<br>
&gt; I discovered this because it RSpec specs when going to 1.9.3: <a href="https://github.com/rspec/rspec-core/issues/506" target="_blank">https://github.com/rspec/rspec-core/issues/506</a><br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; <a href="http://redmine.ruby-lang.org" target="_blank">http://redmine.ruby-lang.org</a><br>
&gt;<br>
</div></div><p></p>
</blockquote></div><br></div>

--485b397dd56d45557c04b24bc3ef--