diff options
author | Jeremy Evans <code@jeremyevans.net> | 2020-06-10 17:50:35 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2020-06-11 07:30:48 -0700 |
commit | 2188d6d160d3ba82432c87277310a4d417e136d5 (patch) | |
tree | f885cb534dc38c06db3431076719436563f96fb9 | |
parent | 5349506eb4c0668fa1d6f512e4dae1021a9a7460 (diff) |
Warn when passing a non-literal block to Kernel#lambda
Implements [Feature #15973]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3209
-rwxr-xr-x | basictest/test.rb | 3 | ||||
-rw-r--r-- | proc.c | 13 | ||||
-rw-r--r-- | test/ruby/test_iterator.rb | 3 | ||||
-rw-r--r-- | test/ruby/test_lambda.rb | 6 |
4 files changed, 20 insertions, 5 deletions
diff --git a/basictest/test.rb b/basictest/test.rb index 25a4298234..a2eb107bce 100755 --- a/basictest/test.rb +++ b/basictest/test.rb @@ -1425,9 +1425,6 @@ marity_test(:test_ok) marity_test(:marity_test) marity_test(:p) -lambda(&method(:test_ok)).call(true) -lambda(&block_get{|a,n| test_ok(a,n)}).call(true, 2) - class ITER_TEST1 def a block_given? @@ -855,6 +855,19 @@ rb_block_lambda(void) static VALUE f_lambda(VALUE _) { + VALUE block_handler = rb_vm_frame_block_handler(GET_EC()->cfp); + + if (block_handler != VM_BLOCK_HANDLER_NONE) { + switch (vm_block_handler_type(block_handler)) { + case block_handler_type_proc: + case block_handler_type_symbol: + case block_handler_type_ifunc: + rb_warn_deprecated("lambda without a literal block", "the proc without lambda"); + default: + break; + } + } + return rb_block_lambda(); } diff --git a/test/ruby/test_iterator.rb b/test/ruby/test_iterator.rb index 54c095338f..820d5591c1 100644 --- a/test/ruby/test_iterator.rb +++ b/test/ruby/test_iterator.rb @@ -339,8 +339,7 @@ class TestIterator < Test::Unit::TestCase marity_test(:marity_test) marity_test(:p) - lambda(&method(:assert)).call(true) - lambda(&get_block{|a,n| assert(a,n)}).call(true, "marity") + get_block{|a,n| assert(a,n)}.call(true, "marity") end def foo diff --git a/test/ruby/test_lambda.rb b/test/ruby/test_lambda.rb index 03b501a6c9..75362e2796 100644 --- a/test/ruby/test_lambda.rb +++ b/test/ruby/test_lambda.rb @@ -74,6 +74,12 @@ class TestLambdaParameters < Test::Unit::TestCase assert_raise(ArgumentError, bug9605) {proc(&plus).call [1,2]} end + def test_warning_for_non_literal_blocks + assert_warn(/lambda without a literal block/, '[ruby-core:93482] [Feature #15973]') do + lambda(&:symbol) + end + end + def pass_along(&block) lambda(&block) end |