ruby-changes:58753
From: Nobuyoshi <ko1@a...>
Date: Tue, 12 Nov 2019 23:01:16 +0900 (JST)
Subject: [ruby-changes:58753] bf34ade7ef (master): Show the name `Kernel#proc` in the warning message
https://git.ruby-lang.org/ruby.git/commit/?id=bf34ade7ef From bf34ade7ef32f89aa5ba238d0a780f23eacb0487 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Tue, 12 Nov 2019 22:58:09 +0900 Subject: Show the name `Kernel#proc` in the warning message diff --git a/proc.c b/proc.c index 1f2e311..560b641 100644 --- a/proc.c +++ b/proc.c @@ -741,7 +741,7 @@ rb_func_lambda_new(rb_block_call_func_t func, VALUE val, int min_argc, int max_a https://github.com/ruby/ruby/blob/trunk/proc.c#L741 static const char proc_without_block[] = "tried to create Proc object without a block"; static VALUE -proc_new(VALUE klass, int8_t is_lambda) +proc_new(VALUE klass, int8_t is_lambda, int8_t kernel) { VALUE procval; const rb_execution_context_t *ec = GET_EC(); @@ -757,11 +757,13 @@ proc_new(VALUE klass, int8_t is_lambda) https://github.com/ruby/ruby/blob/trunk/proc.c#L757 rb_raise(rb_eArgError, proc_without_block); } else { - rb_warn("Capturing the given block using Proc.new is deprecated; use `&block` instead"); + const char *name = kernel ? "Kernel#proc" : "Proc.new"; + rb_warn("Capturing the given block using %s is deprecated; " + "use `&block` instead", name); } } #else - if (0) + if (0); #endif else { rb_raise(rb_eArgError, proc_without_block); @@ -817,7 +819,7 @@ proc_new(VALUE klass, int8_t is_lambda) https://github.com/ruby/ruby/blob/trunk/proc.c#L819 static VALUE rb_proc_s_new(int argc, VALUE *argv, VALUE klass) { - VALUE block = proc_new(klass, FALSE); + VALUE block = proc_new(klass, FALSE, FALSE); rb_obj_call_init_kw(block, argc, argv, RB_PASS_CALLED_KEYWORDS); return block; @@ -826,7 +828,7 @@ rb_proc_s_new(int argc, VALUE *argv, VALUE klass) https://github.com/ruby/ruby/blob/trunk/proc.c#L828 VALUE rb_block_proc(void) { - return proc_new(rb_cProc, FALSE); + return proc_new(rb_cProc, FALSE, FALSE); } /* @@ -839,13 +841,13 @@ rb_block_proc(void) https://github.com/ruby/ruby/blob/trunk/proc.c#L841 static VALUE f_proc(VALUE _) { - return rb_block_proc(); + return proc_new(rb_cProc, FALSE, TRUE); } VALUE rb_block_lambda(void) { - return proc_new(rb_cProc, TRUE); + return proc_new(rb_cProc, TRUE, FALSE); } /* diff --git a/spec/ruby/core/kernel/proc_spec.rb b/spec/ruby/core/kernel/proc_spec.rb index ded2cec..2a79548 100644 --- a/spec/ruby/core/kernel/proc_spec.rb +++ b/spec/ruby/core/kernel/proc_spec.rb @@ -56,7 +56,7 @@ describe "Kernel#proc" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/kernel/proc_spec.rb#L56 -> { some_method { "hello" } - }.should complain(/Capturing the given block using Proc.new is deprecated/) + }.should complain(/Capturing the given block using Kernel#proc is deprecated/) end end end diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb index 467bbf5..f09e58e 100644 --- a/test/ruby/test_proc.rb +++ b/test/ruby/test_proc.rb @@ -55,7 +55,10 @@ class TestProc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_proc.rb#L55 def assert_arity(n) meta = class << self; self; end - meta.class_eval {define_method(:foo, Proc.new)} + b = assert_warn(/Capturing the given block using Proc\.new is deprecated/) do + Proc.new + end + meta.class_eval {define_method(:foo, b)} assert_equal(n, method(:foo).arity) end @@ -1413,7 +1416,9 @@ class TestProc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_proc.rb#L1416 end def method_for_test_proc_without_block_for_symbol - binding.eval('proc') + assert_warn(/Capturing the given block using Kernel#proc is deprecated/) do + binding.eval('proc') + end end def test_proc_without_block_for_symbol -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/