mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
vm_args.c: pass block
* vm_args.c (refine_sym_proc_call): pass block to the method when using refinements. [ruby-core:80219] [Bug #13325] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58015 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
adb3f250fe
commit
49455d6cdc
2 changed files with 35 additions and 4 deletions
|
@ -1769,6 +1769,31 @@ class TestRefinement < Test::Unit::TestCase
|
||||||
assert_equal("Foo#x", FooExtClient.return_proc(&:x).(Foo.new))
|
assert_equal("Foo#x", FooExtClient.return_proc(&:x).(Foo.new))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_symbol_proc_with_block
|
||||||
|
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
|
||||||
|
bug = '[ruby-core:80219] [Bug #13325]'
|
||||||
|
begin;
|
||||||
|
module M
|
||||||
|
refine Class.new do
|
||||||
|
end
|
||||||
|
end
|
||||||
|
class C
|
||||||
|
def call(a, x, &b)
|
||||||
|
b.call(a, &x)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
o = C.new
|
||||||
|
r = nil
|
||||||
|
x = ->(z){r = z}
|
||||||
|
assert_equal(42, o.call(42, x, &:tap))
|
||||||
|
assert_equal(42, r)
|
||||||
|
using M
|
||||||
|
r = nil
|
||||||
|
assert_equal(42, o.call(42, x, &:tap), bug)
|
||||||
|
assert_equal(42, r, bug)
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
|
||||||
module AliasInSubclass
|
module AliasInSubclass
|
||||||
class C
|
class C
|
||||||
def foo
|
def foo
|
||||||
|
|
14
vm_args.c
14
vm_args.c
|
@ -12,6 +12,8 @@ NORETURN(static void raise_argument_error(rb_thread_t *th, const rb_iseq_t *iseq
|
||||||
NORETURN(static void argument_arity_error(rb_thread_t *th, const rb_iseq_t *iseq, const int miss_argc, const int min_argc, const int max_argc));
|
NORETURN(static void argument_arity_error(rb_thread_t *th, const rb_iseq_t *iseq, const int miss_argc, const int min_argc, const int max_argc));
|
||||||
NORETURN(static void argument_kw_error(rb_thread_t *th, const rb_iseq_t *iseq, const char *error, const VALUE keys));
|
NORETURN(static void argument_kw_error(rb_thread_t *th, const rb_iseq_t *iseq, const char *error, const VALUE keys));
|
||||||
VALUE rb_keyword_error_new(const char *error, VALUE keys); /* class.c */
|
VALUE rb_keyword_error_new(const char *error, VALUE keys); /* class.c */
|
||||||
|
static VALUE method_missing(VALUE obj, ID id, int argc, const VALUE *argv,
|
||||||
|
enum method_missing_reason call_status);
|
||||||
|
|
||||||
struct args_info {
|
struct args_info {
|
||||||
/* basic args info */
|
/* basic args info */
|
||||||
|
@ -800,6 +802,7 @@ refine_sym_proc_call(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg))
|
||||||
VALUE obj;
|
VALUE obj;
|
||||||
ID mid;
|
ID mid;
|
||||||
const rb_callable_method_entry_t *me;
|
const rb_callable_method_entry_t *me;
|
||||||
|
rb_thread_t *th;
|
||||||
|
|
||||||
if (argc-- < 1) {
|
if (argc-- < 1) {
|
||||||
rb_raise(rb_eArgError, "no receiver given");
|
rb_raise(rb_eArgError, "no receiver given");
|
||||||
|
@ -807,11 +810,14 @@ refine_sym_proc_call(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg))
|
||||||
obj = *argv++;
|
obj = *argv++;
|
||||||
mid = SYM2ID(callback_arg);
|
mid = SYM2ID(callback_arg);
|
||||||
me = rb_callable_method_entry_with_refinements(CLASS_OF(obj), mid);
|
me = rb_callable_method_entry_with_refinements(CLASS_OF(obj), mid);
|
||||||
if (!me) {
|
th = GET_THREAD();
|
||||||
/* fallback to funcall (e.g. method_missing) */
|
if (!NIL_P(blockarg)) {
|
||||||
return rb_funcall_with_block(obj, mid, argc, argv, blockarg);
|
vm_passed_block_handler_set(th, blockarg);
|
||||||
}
|
}
|
||||||
return vm_call0(GET_THREAD(), obj, mid, argc, argv, me);
|
if (!me) {
|
||||||
|
return method_missing(obj, mid, argc, argv, MISSING_NOENTRY);
|
||||||
|
}
|
||||||
|
return vm_call0(th, obj, mid, argc, argv, me);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Add table
Reference in a new issue