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

ruby-changes:64105

From: Koichi <ko1@a...>
Date: Sat, 12 Dec 2020 06:31:15 +0900 (JST)
Subject: [ruby-changes:64105] 124321e0c7 (master): fix lambda's warning and tests

https://git.ruby-lang.org/ruby.git/commit/?id=124321e0c7

From 124321e0c7ab8dac1ffce78c653cc677f878d5b0 Mon Sep 17 00:00:00 2001
From: Koichi Sasada <ko1@a...>
Date: Sat, 12 Dec 2020 06:29:11 +0900
Subject: fix lambda's warning and tests

There are warning condition bugs and test bugs.
b53ccb9c69abd24e3bdad66cbe4c7e7480eaef16

diff --git a/proc.c b/proc.c
index 7e1985c..749b6a8 100644
--- a/proc.c
+++ b/proc.c
@@ -847,16 +847,8 @@ rb_block_lambda(void) https://github.com/ruby/ruby/blob/trunk/proc.c#L847
     return proc_new(rb_cProc, TRUE, FALSE);
 }
 
-/*
- * call-seq:
- *   lambda { |...| block }  -> a_proc
- *
- * Equivalent to Proc.new, except the resulting Proc objects check the
- * number of parameters passed when called.
- */
-
-static VALUE
-f_lambda(VALUE _)
+static void
+f_lambda_warn(void)
 {
     rb_control_frame_t *cfp = GET_EC()->cfp;
     VALUE block_handler = rb_vm_frame_block_handler(cfp);
@@ -865,20 +857,36 @@ f_lambda(VALUE _) https://github.com/ruby/ruby/blob/trunk/proc.c#L857
         switch (vm_block_handler_type(block_handler)) {
           case block_handler_type_iseq:
             if (RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)->ep == VM_BH_TO_ISEQ_BLOCK(block_handler)->ep) {
-                break;
+                return;
             }
-          case block_handler_type_symbol:
             break;
+          case block_handler_type_symbol:
+            return;
           case block_handler_type_proc:
             if (rb_proc_lambda_p(VM_BH_TO_PROC(block_handler))) {
-                break;
+                return;
             }
+            break;
           case block_handler_type_ifunc:
-            rb_warn_deprecated("lambda without a literal block", "the proc without lambda");
             break;
         }
     }
 
+    rb_warn_deprecated("lambda without a literal block", "the proc without lambda");
+}
+
+/*
+ * call-seq:
+ *   lambda { |...| block }  -> a_proc
+ *
+ * Equivalent to Proc.new, except the resulting Proc objects check the
+ * number of parameters passed when called.
+ */
+
+static VALUE
+f_lambda(VALUE _)
+{
+    f_lambda_warn();
     return rb_block_lambda();
 }
 
diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb
index ca690dc..04c2408 100644
--- a/test/ruby/test_proc.rb
+++ b/test/ruby/test_proc.rb
@@ -316,16 +316,20 @@ class TestProc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_proc.rb#L316
     lambda(&b)
   end
 
+  def_lambda_warning 'test_lambda_warning_pass_symbol_proc', '' do
+    lambda(&:to_s)
+  end
+
   def_lambda_warning 'test_lambda_warning_pass_proc', /deprecated/ do
     b = proc{}
     lambda(&b)
   end
 
-  def_lambda_warning 'test_lambda_warning_pass_proc', /deprecated/ do
+  def_lambda_warning 'test_lambda_warning_pass_block', /deprecated/ do
     helper_test_warn_lamda_with_passed_block{}
   end
 
-  def_lambda_warning 'test_lambda_warning_pass_proc', '' do
+  def_lambda_warning 'test_lambda_warning_pass_block_symbol_proc', '' do
     # Symbol#to_proc returns lambda
     helper_test_warn_lamda_with_passed_block(&:to_s)
   end
-- 
cgit v0.10.2


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

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