diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-05-13 09:13:33 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-05-13 09:13:33 +0900 |
| commit | b4657182da44febeccd5f22af636bceda776122f (patch) | |
| tree | 14553befe49eb23a0118014da900b6fc347f2922 | |
| parent | bcbf078ebd4c3346982d0dc8e125da12b61a04bc (diff) | |
| download | mruby-b4657182da44febeccd5f22af636bceda776122f.tar.gz mruby-b4657182da44febeccd5f22af636bceda776122f.zip | |
convert &arg using to_proc; fix #2242
| -rw-r--r-- | src/vm.c | 3 | ||||
| -rw-r--r-- | test/t/proc.rb | 17 |
2 files changed, 20 insertions, 0 deletions
@@ -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; diff --git a/test/t/proc.rb b/test/t/proc.rb index 33c3a0ef2..e871e637e 100644 --- a/test/t/proc.rb +++ b/test/t/proc.rb @@ -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 |
