https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112015-03-06T13:00:48ZRuby Issue Tracking SystemRuby master - Bug #10929: NilClass#to_proc and & don't mix?https://bugs.ruby-lang.org/issues/10929?journal_id=517872015-03-06T13:00:48Zhanachin (Seiei Miyagi)hanachin@gmail.com
<ul><li><strong>File</strong> <a href="/attachments/5101">block_from_nil.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/5101/block_from_nil.patch">block_from_nil.patch</a> added</li></ul><p>I wrote a patch for this issue.</p>
<pre><code class="diff syntaxhl" data-language="diff"><span class="gh">diff --git bootstraptest/test_block.rb bootstraptest/test_block.rb
index cdc5960..4347fdd 100644
</span><span class="gd">--- bootstraptest/test_block.rb
</span><span class="gi">+++ bootstraptest/test_block.rb
</span><span class="p">@@ -611,3 +611,17 @@</span> assert_equal 'ok', %q{
end
'ok'
}
<span class="gi">+
+assert_equal 'ok', %q{
+ class NilClass
+ def to_proc
+ Proc.new {|x| x }
+ end
+ end
+
+ def foo(&blk)
+ blk.call('ok')
+ end
+
+ foo(&nil)
+}, '<a href="/issues/10929">[ruby-core:68384]</a> [Bug #10929]'
</span><span class="gh">diff --git vm_args.c vm_args.c
index cf7256b..e1cb8ac 100644
</span><span class="gd">--- vm_args.c
</span><span class="gi">+++ vm_args.c
</span><span class="p">@@ -755,7 +755,7 @@</span> vm_caller_setup_arg_block(const rb_thread_t *th, rb_control_frame_t *reg_cfp, rb
<span class="err">
</span> proc = *(--reg_cfp->sp);
<span class="err">
</span><span class="gd">- if (proc != Qnil) {
</span><span class="gi">+ if (proc != Qnil || rb_respond_to(Qnil, idTo_proc)) {
</span> if (!rb_obj_is_proc(proc)) {
VALUE b;
</code></pre> Ruby master - Bug #10929: NilClass#to_proc and & don't mix?https://bugs.ruby-lang.org/issues/10929?journal_id=518072015-03-08T22:43:52Zko1 (Koichi Sasada)
<ul><li><strong>Assignee</strong> set to <i>matz (Yukihiro Matsumoto)</i></li></ul><p>I'm not sure we support it or not.<br>
For me, it is easy to understand that passing <code>nil</code> is special case, passing no block.</p> Ruby master - Bug #10929: NilClass#to_proc and & don't mix?https://bugs.ruby-lang.org/issues/10929?journal_id=831692019-12-16T15:15:44Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Feedback</i></li></ul><p>The suggested change is harmful. It will break delegation: <code>def foo(&blk); bar(&blk); end; foo()</code>.</p>
<p>Ruby allows redefinition of <code>Integer#/</code> which is incredibly harmful, so it is possible to allow <code>NilClass#to_proc</code>. But do you really want to allow that?</p> Ruby master - Bug #10929: NilClass#to_proc and & don't mix?https://bugs.ruby-lang.org/issues/10929?journal_id=838282020-01-14T02:31:42Zko1 (Koichi Sasada)
<ul><li><strong>Status</strong> changed from <i>Feedback</i> to <i>Rejected</i></li></ul><p>it can break delegation methods.</p>