1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Proc made by Symbol#to_proc should be a lambda [Bug #16260]

With refinements, too.
This commit is contained in:
Nobuyoshi Nakada 2020-02-22 00:32:43 +09:00
parent 5cab86f3b0
commit 8c5ca318cb
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
4 changed files with 10 additions and 3 deletions

View file

@ -19,11 +19,11 @@ VALUE rb_proc_location(VALUE self);
st_index_t rb_hash_proc(st_index_t hash, VALUE proc);
int rb_block_arity(void);
int rb_block_min_max_arity(int *max);
VALUE rb_func_lambda_new(rb_block_call_func_t func, VALUE val, int min_argc, int max_argc);
VALUE rb_block_to_s(VALUE self, const struct rb_block *block, const char *additional_info);
MJIT_SYMBOL_EXPORT_BEGIN
VALUE rb_func_proc_new(rb_block_call_func_t func, VALUE val);
VALUE rb_func_lambda_new(rb_block_call_func_t func, VALUE val, int min_argc, int max_argc);
VALUE rb_iseq_location(const struct rb_iseq_struct *iseq);
VALUE rb_sym_to_proc(VALUE sym);
MJIT_SYMBOL_EXPORT_END

2
proc.c
View file

@ -739,7 +739,7 @@ rb_func_proc_new(rb_block_call_func_t func, VALUE val)
return cfunc_proc_new(rb_cProc, (VALUE)ifunc, 0);
}
VALUE
MJIT_FUNC_EXPORTED VALUE
rb_func_lambda_new(rb_block_call_func_t func, VALUE val, int min_argc, int max_argc)
{
struct vm_ifunc *ifunc = rb_vm_ifunc_new(func, (void *)val, min_argc, max_argc);

View file

@ -169,6 +169,9 @@ class TestSymbol < Test::Unit::TestCase
def _test_to_proc_arg_with_refinements_call(&block)
block.call TestToPRocArgWithRefinements.new
end
def _test_to_proc_with_refinements_call(&block)
block
end
using Module.new {
refine TestToPRocArgWithRefinements do
def hoge
@ -180,6 +183,10 @@ class TestSymbol < Test::Unit::TestCase
assert_equal(:hoge, _test_to_proc_arg_with_refinements_call(&:hoge))
end
def test_to_proc_lambda_with_refinements
assert_predicate(_test_to_proc_with_refinements_call(&:hoge), :lambda?)
end
def self._test_to_proc_arg_with_refinements_call(&block)
block.call TestToPRocArgWithRefinements.new
end

View file

@ -869,7 +869,7 @@ vm_caller_setup_arg_block(const rb_execution_context_t *ec, rb_control_frame_t *
rb_ary_push(callback_arg, block_code);
rb_ary_push(callback_arg, ref);
OBJ_FREEZE_RAW(callback_arg);
func = rb_func_proc_new(refine_sym_proc_call, callback_arg);
func = rb_func_lambda_new(refine_sym_proc_call, callback_arg, 0, UNLIMITED_ARGUMENTS);
rb_hash_aset(ref, block_code, func);
}
block_code = func;