https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112016-08-12T05:47:52ZRuby Issue Tracking SystemRuby master - Bug #12671: Hash#to_proc result is not a lambda, but enforces arityhttps://bugs.ruby-lang.org/issues/12671?journal_id=600752016-08-12T05:47:52Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>None-lambda doesn't mean that it never checks its arguments.<br>
And if it's a lambda, it doesn't match the <code>arity</code> value.</p>
<p>As for the implementation detail, there is no room for arity in <code>ifunc</code>s.</p> Ruby master - Bug #12671: Hash#to_proc result is not a lambda, but enforces arityhttps://bugs.ruby-lang.org/issues/12671?journal_id=600762016-08-12T06:46:32Zheadius (Charles Nutter)headius@headius.com
<ul></ul><p>JRuby implements Hash#to_proc as:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">class</span> <span class="nc">Hash</span>
<span class="k">def</span> <span class="nf">to_proc</span>
<span class="nb">method</span><span class="p">(</span><span class="ss">:[]</span><span class="p">).</span><span class="nf">to_proc</span>
<span class="k">end</span>
<span class="k">end</span>
</code></pre>
<p>This allows us to present the proc as a lambda with correct arity:</p>
<pre><code>$ jruby -e "pr = {}.to_proc; puts pr.arity; puts pr.lambda?"
1
true
</code></pre>
<p>It works for MRI too:</p>
<pre><code>$ ruby23 -e "class Hash; def to_proc; method(:[]).to_proc; end; end; pr = {}.to_proc; puts pr.arity; puts pr.lambda?"
1
true
</code></pre>
<p>I think this is more representative of this proc's behavior. Can MRI do it this way?</p> Ruby master - Bug #12671: Hash#to_proc result is not a lambda, but enforces arityhttps://bugs.ruby-lang.org/issues/12671?journal_id=846832020-03-16T13:45:39Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul></ul><p>This ticket was briefly discussed at today's dev meeting, and matz said that the result of Hash#to_proc should be a lambda.</p> Ruby master - Bug #12671: Hash#to_proc result is not a lambda, but enforces arityhttps://bugs.ruby-lang.org/issues/12671?journal_id=846852020-03-16T14:38:44Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Applied in changeset <a class="changeset" title="`Proc` made by `Hash#to_proc` should be a lambda [Bug #12671] Like `Symbol#to_proc` (f0b815dc670..." href="https://bugs.ruby-lang.org/projects/ruby-master/repository/git/revisions/d514ba8e17106c6d159c3902ac5456d6269731f8">git|d514ba8e17106c6d159c3902ac5456d6269731f8</a>.</p>
<hr>
<p><code>Proc</code> made by <code>Hash#to_proc</code> should be a lambda [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Hash#to_proc result is not a lambda, but enforces arity (Closed)" href="https://bugs.ruby-lang.org/issues/12671">#12671</a>]</p>
<p>Like <code>Symbol#to_proc</code> (f0b815dc670b61eba1daaa67a8613ac431d32b16)</p> Ruby master - Bug #12671: Hash#to_proc result is not a lambda, but enforces arityhttps://bugs.ruby-lang.org/issues/12671?journal_id=867612020-07-27T20:14:06Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul><li><strong>Status</strong> changed from <i>Closed</i> to <i>Open</i></li></ul><p>Is there a reason why the arity was not fixed to <code>1</code> (instead of <code>-1</code>)?</p> Ruby master - Bug #12671: Hash#to_proc result is not a lambda, but enforces arityhttps://bugs.ruby-lang.org/issues/12671?journal_id=867712020-07-28T18:30:54ZEregon (Benoit Daloze)
<ul></ul><p>Looking at the commit, should Hash#to_proc use <code>rb_func_lambda_new()</code> instead of <code>rb_func_proc_new()</code>? (and then <code>rb_func_proc_new</code> is unused)<br>
Also it seems confusing that <code>rb_func_proc_new()</code> creates a lambda, so using <code>rb_func_lambda_new()</code> seems better here.<br>
Code changed quite a bit though around there.</p> Ruby master - Bug #12671: Hash#to_proc result is not a lambda, but enforces arityhttps://bugs.ruby-lang.org/issues/12671?journal_id=867722020-07-28T18:42:55ZEregon (Benoit Daloze)
<ul></ul><p>Proposed fix (simple as it gets): <a href="https://github.com/ruby/ruby/pull/3370" class="external">https://github.com/ruby/ruby/pull/3370</a></p> Ruby master - Bug #12671: Hash#to_proc result is not a lambda, but enforces arityhttps://bugs.ruby-lang.org/issues/12671?journal_id=868032020-07-29T16:10:27ZEregon (Benoit Daloze)
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Applied in changeset <a class="changeset" title="Fix arity of Hash#to_proc [Bug #12671]" href="https://bugs.ruby-lang.org/projects/ruby-master/repository/git/revisions/241244739f2b721ac7aa0961bd90d904c5e3fff6">git|241244739f2b721ac7aa0961bd90d904c5e3fff6</a>.</p>
<hr>
<p>Fix arity of Hash#to_proc [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Hash#to_proc result is not a lambda, but enforces arity (Closed)" href="https://bugs.ruby-lang.org/issues/12671">#12671</a>]</p>