From f3e927b0cc1fcbf03abea7f66b1a3736a270a8de Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Wed, 10 Jun 2020 15:17:54 -0700 Subject: Make proc/Proc.new without block an error instead of warning The warning for these was added in 2.7. --- bootstraptest/test_flow.rb | 8 ++++---- bootstraptest/test_proc.rb | 4 ++-- proc.c | 42 +------------------------------------- spec/ruby/core/kernel/proc_spec.rb | 2 +- spec/ruby/core/proc/new_spec.rb | 2 +- test/ruby/test_proc.rb | 16 ++------------- 6 files changed, 11 insertions(+), 63 deletions(-) diff --git a/bootstraptest/test_flow.rb b/bootstraptest/test_flow.rb index 9da6d45cbd..35f19db588 100644 --- a/bootstraptest/test_flow.rb +++ b/bootstraptest/test_flow.rb @@ -534,11 +534,11 @@ assert_equal %Q{ENSURE\n}, %q{ ['[ruby-core:39125]', %q{ class Bug5234 include Enumerable - def each + def each(&block) begin yield :foo ensure - proc + proc(&block) end end end @@ -547,11 +547,11 @@ assert_equal %Q{ENSURE\n}, %q{ ['[ruby-dev:45656]', %q{ class Bug6460 include Enumerable - def each + def each(&block) begin yield :foo ensure - 1.times { Proc.new } + 1.times { Proc.new(&block) } end end end diff --git a/bootstraptest/test_proc.rb b/bootstraptest/test_proc.rb index 6d2c557c3c..637603243d 100644 --- a/bootstraptest/test_proc.rb +++ b/bootstraptest/test_proc.rb @@ -367,8 +367,8 @@ assert_equal 'ok', %q{ assert_equal 'ok', %q{ class Foo - def call_it - p = Proc.new + def call_it(&block) + p = Proc.new(&block) p.call end end diff --git a/proc.c b/proc.c index 249bc65a70..ffc87b7ea3 100644 --- a/proc.c +++ b/proc.c @@ -21,10 +21,6 @@ #include "iseq.h" #include "vm_core.h" -/* Proc.new with no block will raise an exception in the future - * versions */ -#define PROC_NEW_REQUIRES_BLOCK 0 - #if !defined(__GNUC__) || __GNUC__ < 5 || defined(__MINGW32__) # define NO_CLOBBERED(v) (*(volatile VALUE *)&(v)) #else @@ -757,25 +753,7 @@ proc_new(VALUE klass, int8_t is_lambda, int8_t kernel) VALUE block_handler; if ((block_handler = rb_vm_frame_block_handler(cfp)) == VM_BLOCK_HANDLER_NONE) { -#if !PROC_NEW_REQUIRES_BLOCK - cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); - - if ((block_handler = rb_vm_frame_block_handler(cfp)) != VM_BLOCK_HANDLER_NONE) { - if (is_lambda) { - rb_raise(rb_eArgError, proc_without_block); - } - else { - const char *name = kernel ? "Kernel#proc" : "Proc.new"; - rb_warn_deprecated("Capturing the given block using %s", - "`&block`", name); - } - } -#else - if (0); -#endif - else { - rb_raise(rb_eArgError, proc_without_block); - } + rb_raise(rb_eArgError, proc_without_block); } /* block is in cf */ @@ -2084,25 +2062,7 @@ rb_mod_define_method(int argc, VALUE *argv, VALUE mod) name = argv[0]; id = rb_check_id(&name); if (argc == 1) { -#if PROC_NEW_REQUIRES_BLOCK body = rb_block_lambda(); -#else - const rb_execution_context_t *ec = GET_EC(); - VALUE block_handler = rb_vm_frame_block_handler(ec->cfp); - if (block_handler == VM_BLOCK_HANDLER_NONE) rb_raise(rb_eArgError, proc_without_block); - - switch (vm_block_handler_type(block_handler)) { - case block_handler_type_proc: - body = VM_BH_TO_PROC(block_handler); - break; - case block_handler_type_symbol: - body = rb_sym_to_proc(VM_BH_TO_SYMBOL(block_handler)); - break; - case block_handler_type_iseq: - case block_handler_type_ifunc: - body = rb_vm_make_lambda(ec, VM_BH_TO_CAPT_BLOCK(block_handler), rb_cProc); - } -#endif } else { body = argv[1]; diff --git a/spec/ruby/core/kernel/proc_spec.rb b/spec/ruby/core/kernel/proc_spec.rb index 2a79548313..3930715ebd 100644 --- a/spec/ruby/core/kernel/proc_spec.rb +++ b/spec/ruby/core/kernel/proc_spec.rb @@ -48,7 +48,7 @@ describe "Kernel#proc" do end end - ruby_version_is "2.7" do + ruby_version_is "2.7" ... "2.8" do it "can be created when called with no block" do def some_method proc diff --git a/spec/ruby/core/proc/new_spec.rb b/spec/ruby/core/proc/new_spec.rb index cc033467e5..faaf85fea5 100644 --- a/spec/ruby/core/proc/new_spec.rb +++ b/spec/ruby/core/proc/new_spec.rb @@ -203,7 +203,7 @@ describe "Proc.new without a block" do end end - ruby_version_is "2.7" do + ruby_version_is "2.7" ... "2.8" do it "can be created if invoked from within a method with a block" do -> { ProcSpecs.new_proc_in_method { "hello" } }.should complain(/Capturing the given block using Proc.new is deprecated/) end diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb index 14b79380e2..765b400dbe 100644 --- a/test/ruby/test_proc.rb +++ b/test/ruby/test_proc.rb @@ -53,11 +53,9 @@ class TestProc < Test::Unit::TestCase assert_equal(5, x) end - def assert_arity(n) + def assert_arity(n, &block) meta = class << self; self; end - b = assert_warn(/Capturing the given block using Proc\.new is deprecated/) do - Proc.new - end + b = Proc.new(&block) meta.class_eval { remove_method(:foo_arity) if method_defined?(:foo_arity) define_method(:foo_arity, b) @@ -1433,16 +1431,6 @@ class TestProc < Test::Unit::TestCase end; end - def method_for_test_proc_without_block_for_symbol - assert_warn(/Capturing the given block using Kernel#proc is deprecated/) do - binding.eval('proc') - end - end - - def test_proc_without_block_for_symbol - assert_equal('1', method_for_test_proc_without_block_for_symbol(&:to_s).call(1), '[Bug #14782]') - end - def test_compose f = proc {|x| x * 2} g = proc {|x| x + 1} -- cgit v1.2.3