https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112019-07-30T07:34:03ZRuby Issue Tracking SystemRuby master - Bug #16008: Ripper hshptn node drops informationhttps://redmine.ruby-lang.org/issues/16008?journal_id=802542019-07-30T07:34:03Zko1 (Koichi Sasada)
<ul><li><strong>Assignee</strong> set to <i>nobu (Nobuyoshi Nakada)</i></li></ul> Ruby master - Bug #16008: Ripper hshptn node drops informationhttps://redmine.ruby-lang.org/issues/16008?journal_id=819582019-10-08T16:38:22Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>File</strong> <a href="/attachments/8098">ripper-hash-pattern-on_label-16008.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/8098/ripper-hash-pattern-on_label-16008.patch">ripper-hash-pattern-on_label-16008.patch</a> added</li></ul><p>I believe this issue comes from <code>new_unique_key_hash</code>, which expects the <code>kw_args</code> member of the <code>hshptn</code> node to be in a certain format (see <a href="https://github.com/ruby/ruby/blob/master/parse.y#L811" class="external">https://github.com/ruby/ruby/blob/master/parse.y#L811</a>). If you modify the size of the array, it can't recognize the results to determine if the hash is unique, and treats it as an error, which results in a <code>nil</code> value being used.</p>
<p>You can currently work around this by including your metadata as an extra member of the location array:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"> <span class="k">def</span> <span class="nf">on_label</span><span class="p">(</span><span class="n">token</span><span class="p">)</span>
<span class="k">super</span><span class="p">.</span><span class="nf">tap</span><span class="p">{</span><span class="o">|</span><span class="n">a</span><span class="o">|</span> <span class="n">a</span><span class="p">.</span><span class="nf">last</span><span class="p">.</span><span class="nf">push</span><span class="p">(</span><span class="ss">:metadata</span><span class="o">=></span><span class="kp">nil</span><span class="p">)}</span>
<span class="k">end</span>
</code></pre>
<p>It may be better to return the array as-is in case the format doesn't match what is expected, and only treat actual duplicate keys as errors. The attached patch implements that approach.</p> Ruby master - Bug #16008: Ripper hshptn node drops informationhttps://redmine.ruby-lang.org/issues/16008?journal_id=819682019-10-09T08:21:03Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>It works in this case, but not generic.<br>
My WIP patch is <a href="https://github.com/nobu/ruby/tree/ripper.value" class="external">https://github.com/nobu/ruby/tree/ripper.value</a></p> Ruby master - Bug #16008: Ripper hshptn node drops informationhttps://redmine.ruby-lang.org/issues/16008?journal_id=827972019-11-26T14:56:49Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li><li><strong>Backport</strong> changed from <i>2.5: UNKNOWN, 2.6: UNKNOWN</i> to <i>2.5: DONTNEED, 2.6: DONTNEED</i></li></ul> Ruby master - Bug #16008: Ripper hshptn node drops informationhttps://redmine.ruby-lang.org/issues/16008?journal_id=1056152023-12-10T15:24:33Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Related to</strong> <i><a class="issue tracker-1 status-5 priority-4 priority-default closed" href="/issues/20055">Bug #20055</a>: Ripper seems to skip some checks like `void value expression` and `duplicated variable name`</i> added</li></ul>