https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112015-11-20T06:25:07ZRuby Issue Tracking SystemRuby master - Bug #11718: Constant access on `nil`https://redmine.ruby-lang.org/issues/11718?journal_id=549832015-11-20T06:25:07ZHanmac (Hans Mackowiak)hanmac@gmx.de
<ul></ul><p>hm it might be that <code>nil::Foo</code> is parsed as <code>::Foo</code> which is doing the top-level access.</p>
<p>but i am not deep enough in the parser to fix that.</p> Ruby master - Bug #11718: Constant access on `nil`https://redmine.ruby-lang.org/issues/11718?journal_id=549892015-11-20T09:18:44ZEregon (Benoit Daloze)
<ul></ul><p>I think this should really raise an error like:</p>
<pre><code>$ ruby -e 'p nil::String'
-e:1:in `<main>': nil is not a class/module (TypeError)
</code></pre> Ruby master - Bug #11718: Constant access on `nil`https://redmine.ruby-lang.org/issues/11718?journal_id=549902015-11-20T09:45:08ZHanmac (Hans Mackowiak)hanmac@gmx.de
<ul></ul><p>yeah that should raise an error. A little test shows that this exist a while way back:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="nb">p</span> <span class="kp">nil</span><span class="o">::</span><span class="no">String</span>
</code></pre>
<p>for 1.9.3:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="no">String</span>
</code></pre>
<p>for 1.8.7:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="c1"># is not a class/module (TypeError)</span>
</code></pre> Ruby master - Bug #11718: Constant access on `nil`https://redmine.ruby-lang.org/issues/11718?journal_id=550422015-11-23T14:25:41Zelia (Elia Schito)elia@schito.me
<ul></ul><p>looks like it's somehow intended behavior</p>
<p><a href="https://github.com/ruby/ruby/blob/trunk/insns.def#L179-L190" class="external">https://github.com/ruby/ruby/blob/trunk/insns.def#L179-L190</a></p>
<pre><code> /**
@c variable
@e
Get constant variable id. If klass is Qnil, constants
are searched in the current scope. If klass is Qfalse, constants
are searched as top level constants. Otherwise, get constant under klass
class or module.
@j 定数 id の値を得る。
klass が Qnil なら、そのスコープで得られる定数の値を得る。
Qfalse なら、トップレベルスコープを得る。
それ以外なら、klass クラスの下の定数を得る。
*/
</code></pre>
<p>apparently introduced here: <a href="https://github.com/ruby/ruby/commit/d84f9b16946bca06ce0557ebe99152d7d445c9ec" class="external">https://github.com/ruby/ruby/commit/d84f9b16946bca06ce0557ebe99152d7d445c9ec</a> to resolve bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Singleton class expression (class << obj) should make be indivisual namespaces (Closed)" href="https://redmine.ruby-lang.org/issues/10943">#10943</a></p> Ruby master - Bug #11718: Constant access on `nil`https://redmine.ruby-lang.org/issues/11718?journal_id=550432015-11-23T14:40:32ZEregon (Benoit Daloze)
<ul></ul><p>I don't think it's intended, that commit should not introduce new behavior except on singleton class constants.<br>
<a class="user active user-mention" href="https://redmine.ruby-lang.org/users/17">@ko1 (Koichi Sasada)</a>: Could you confirm this is a bug?</p> Ruby master - Bug #11718: Constant access on `nil`https://redmine.ruby-lang.org/issues/11718?journal_id=550522015-11-24T09:23:51Zko1 (Koichi Sasada)
<ul></ul><p>This is a (intentional) bug. Because I expect nobody reveal such code :p</p> Ruby master - Bug #11718: Constant access on `nil`https://redmine.ruby-lang.org/issues/11718?journal_id=553002015-12-07T07:57:38Zko1 (Koichi Sasada)
<ul><li><strong>Assignee</strong> set to <i>ko1 (Koichi Sasada)</i></li></ul> Ruby master - Bug #11718: Constant access on `nil`https://redmine.ruby-lang.org/issues/11718?journal_id=553022015-12-07T10:51:33Zko1 (Koichi Sasada)
<ul></ul><ul>
<li>This is a bug, so that anyone should not rely on this behavior.</li>
<li>This is a bug, so that this bug should be fixed</li>
<li>But not critical, so 2.3 can remain this behavior. It should be fix in a future.</li>
</ul> Ruby master - Bug #11718: Constant access on `nil`https://redmine.ruby-lang.org/issues/11718?journal_id=553472015-12-08T06:41:48ZHanmac (Hans Mackowiak)hanmac@gmx.de
<ul></ul><p>@Koichi: good that you classify it, for a moment i thought that might be an feature ;P</p> Ruby master - Bug #11718: Constant access on `nil`https://redmine.ruby-lang.org/issues/11718?journal_id=807372019-08-14T05:51:14Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>File</strong> <a href="/attachments/7996">nil-const-access-11718.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/7996/nil-const-access-11718.patch">nil-const-access-11718.patch</a> added</li></ul><p>This bug is still present in the master branch. Attached is a patch that fixes it. It adds a second argument to the getconstant instruction. It would probably be better for performance to add a separate instruction for the case where this is needed, but I'm not sure it is worth it. With the patch:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="kp">nil</span><span class="o">::</span><span class="no">Object</span>
<span class="c1"># TypeError (nil is not a class/module)</span>
</code></pre> Ruby master - Bug #11718: Constant access on `nil`https://redmine.ruby-lang.org/issues/11718?journal_id=807392019-08-14T06:35:57Zko1 (Koichi Sasada)
<ul></ul><p>:+1: great patch! could you commit it?</p> Ruby master - Bug #11718: Constant access on `nil`https://redmine.ruby-lang.org/issues/11718?journal_id=807432019-08-14T07:19:33Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>I think it can be an operand of <code>getconst</code> than an argument on the stack, while it is always a constant.</p> Ruby master - Bug #11718: Constant access on `nil`https://redmine.ruby-lang.org/issues/11718?journal_id=807542019-08-14T16:08:49Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul></ul><p>nobu: I agree, making it an operand instead of a stack argument makes more sense. I'm currently testing a patch for that and will commit if it passes.</p> Ruby master - Bug #11718: Constant access on `nil`https://redmine.ruby-lang.org/issues/11718?journal_id=807572019-08-14T16:51:22Zjeremyevans (Jeremy Evans)code@jeremyevans.net
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Applied in changeset <a class="changeset" title="Remove support for nil::Constant This was an intentional bug added in 1.9. The approach taken h..." href="https://redmine.ruby-lang.org/projects/ruby-master/repository/git/revisions/fbcd0652944568c43a6ae427960d909d62ce6a8d">git|fbcd0652944568c43a6ae427960d909d62ce6a8d</a>.</p>
<hr>
<p>Remove support for nil::Constant</p>
<p>This was an intentional bug added in 1.9.</p>
<p>The approach taken here is to add a second operand to the<br>
getconstant instruction for whether nil should be allowed and<br>
treated as current scope.</p>
<p>Fixes [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Constant access on `nil` (Closed)" href="https://redmine.ruby-lang.org/issues/11718">#11718</a>]</p> Ruby master - Bug #11718: Constant access on `nil`https://redmine.ruby-lang.org/issues/11718?journal_id=807592019-08-14T18:03:07Zko1 (Koichi Sasada)
<ul></ul><blockquote>
<p>I think it can be an operand of getconst than an argument on the stack, while it is always a constant.</p>
</blockquote>
<p>No. It should not be an new operand because we need to change tools which depends on current bytecode.</p>