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

vm_insnhelper.c: allow to_ary

* vm_insnhelper.c (vm_callee_setup_arg{_complex,}): try conversion
  by to_ary for a lambda, as well as a proc.
  [ruby-core:65887] [Bug #9605]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48193 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-10-30 02:16:15 +00:00
parent 44d2958e3b
commit e95e524782
3 changed files with 34 additions and 2 deletions

View file

@ -1,3 +1,9 @@
Thu Oct 30 11:16:13 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* vm_insnhelper.c (vm_callee_setup_arg{_complex,}): try conversion
by to_ary for a lambda, as well as a proc.
[ruby-core:65887] [Bug #9605]
Wed Oct 29 21:13:23 2014 Nobuyoshi Nakada <nobu@ruby-lang.org> Wed Oct 29 21:13:23 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (gettable_gen): warn circular argument reference, for * parse.y (gettable_gen): warn circular argument reference, for

View file

@ -71,6 +71,32 @@ class TestLambdaParameters < Test::Unit::TestCase
assert_raise(ArgumentError, bug9605) {proc(&plus).call [1,2]} assert_raise(ArgumentError, bug9605) {proc(&plus).call [1,2]}
end end
def yield_1(arg)
yield arg
end
tap do |;bug9605, expected, result|
bug9605 = '[ruby-core:65887] [Bug #9605] arity check should be relaxed'
expected = [1,2,3]
[
["array", expected],
["to_ary", Struct.new(:to_ary).new(expected)],
].product \
[
["proc", proc {|a, b, c| [a, b, c]}],
["lambda", lambda {|a, b, c| [a, b, c]}],
] do
|(vtype, val), (btype, block)|
define_method("test_yeild_relaxed(#{vtype},&#{btype})") do
result = assert_nothing_raised(ArgumentError, bug9605) {
break yield_1(val, &block)
}
assert_equal(expected, result, bug9605)
end
end
end
def foo def foo
assert_equal(nil, ->(&b){ b }.call) assert_equal(nil, ->(&b){ b }.call)
end end

View file

@ -1140,7 +1140,7 @@ vm_callee_setup_arg_complex(rb_thread_t *th, rb_call_info_t *ci, const rb_iseq_t
long len; long len;
if (!splattable || if (!splattable ||
argc != 1 || argc != 1 ||
!RB_TYPE_P(arg0 = argv[0], T_ARRAY) || NIL_P(arg0 = rb_check_array_type(argv[0])) ||
(len = RARRAY_LEN(arg0)) < (long)min || (len = RARRAY_LEN(arg0)) < (long)min ||
(len > (long)max && max != UNLIMITED_ARGUMENTS)) { (len > (long)max && max != UNLIMITED_ARGUMENTS)) {
argument_error(iseq, argc, min, max); argument_error(iseq, argc, min, max);
@ -1238,7 +1238,7 @@ vm_callee_setup_arg(rb_thread_t *th, rb_call_info_t *ci, const rb_iseq_t *iseq,
long len; long len;
if (!(is_lambda > 1) || if (!(is_lambda > 1) ||
ci->argc != 1 || ci->argc != 1 ||
!RB_TYPE_P(arg0 = argv[0], T_ARRAY) || NIL_P(arg0 = rb_check_array_type(argv[0])) ||
(len = RARRAY_LEN(arg0)) != (long)iseq->argc) { (len = RARRAY_LEN(arg0)) != (long)iseq->argc) {
argument_error(iseq, ci->argc, iseq->argc, iseq->argc); argument_error(iseq, ci->argc, iseq->argc, iseq->argc);
} }