convert &arg using to_proc; fix #2242

parent bcbf078e
......@@ -1286,6 +1286,9 @@ RETRY_TRY_BLOCK:
int len = m1 + o + r + m2;
mrb_value *blk = &argv[argc < 0 ? 1 : argc];
if (!mrb_nil_p(*blk) && mrb_type(*blk) != MRB_TT_PROC) {
*blk = mrb_convert_type(mrb, *blk, MRB_TT_PROC, "Proc", "to_proc");
}
if (argc < 0) {
struct RArray *ary = mrb_ary_ptr(regs[1]);
argv = ary->ptr;
......
......@@ -131,3 +131,20 @@ assert('Proc#return_does_not_break_self') do
assert_equal nil, c.return_nil
assert_equal c, c.block.call
end
assert('&obj call to_proc if defined') do
pr = Proc.new{}
def mock(&b)
b
end
assert_equal pr.object_id, mock(&pr).object_id
assert_equal pr, mock(&pr)
obj = Object.new
def obj.to_proc
Proc.new{ :from_to_proc }
end
assert_equal :from_to_proc, mock(&obj).call
assert_raise(TypeError){ mock(&(Object.new)) }
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment