[前][次][番号順一覧][スレッド一覧]

ruby-changes:36112

From: nobu <ko1@a...>
Date: Thu, 30 Oct 2014 11:16:27 +0900 (JST)
Subject: [ruby-changes:36112] nobu:r48193 (trunk): vm_insnhelper.c: allow to_ary

nobu	2014-10-30 11:16:15 +0900 (Thu, 30 Oct 2014)

  New Revision: 48193

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48193

  Log:
    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]

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_lambda.rb
    trunk/vm_insnhelper.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48192)
+++ ChangeLog	(revision 48193)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Oct 30 11:16:13 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@r...>
 
 	* parse.y (gettable_gen): warn circular argument reference, for
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 48192)
+++ vm_insnhelper.c	(revision 48193)
@@ -1140,7 +1140,7 @@ vm_callee_setup_arg_complex(rb_thread_t https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1140
 	long len;
 	if (!splattable ||
 	    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 > (long)max && max != UNLIMITED_ARGUMENTS)) {
 	    argument_error(iseq, argc, min, max);
@@ -1238,7 +1238,7 @@ vm_callee_setup_arg(rb_thread_t *th, rb_ https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1238
 	    long len;
 	    if (!(is_lambda > 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) {
 		argument_error(iseq, ci->argc, iseq->argc, iseq->argc);
 	    }
Index: test/ruby/test_lambda.rb
===================================================================
--- test/ruby/test_lambda.rb	(revision 48192)
+++ test/ruby/test_lambda.rb	(revision 48193)
@@ -71,6 +71,32 @@ class TestLambdaParameters < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_lambda.rb#L71
     assert_raise(ArgumentError, bug9605) {proc(&plus).call [1,2]}
   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
     assert_equal(nil, ->(&b){ b }.call)
   end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]