Warn when passing a non-literal block to Kernel#lambda
Implements [Feature #15973]
This commit is contained in:
parent
5349506eb4
commit
2188d6d160
Notes:
git
2020-06-11 23:31:13 +09:00
@ -1425,9 +1425,6 @@ marity_test(:test_ok)
|
|||||||
marity_test(:marity_test)
|
marity_test(:marity_test)
|
||||||
marity_test(:p)
|
marity_test(:p)
|
||||||
|
|
||||||
lambda(&method(:test_ok)).call(true)
|
|
||||||
lambda(&block_get{|a,n| test_ok(a,n)}).call(true, 2)
|
|
||||||
|
|
||||||
class ITER_TEST1
|
class ITER_TEST1
|
||||||
def a
|
def a
|
||||||
block_given?
|
block_given?
|
||||||
|
13
proc.c
13
proc.c
@ -855,6 +855,19 @@ rb_block_lambda(void)
|
|||||||
static VALUE
|
static VALUE
|
||||||
f_lambda(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();
|
return rb_block_lambda();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,8 +339,7 @@ class TestIterator < Test::Unit::TestCase
|
|||||||
marity_test(:marity_test)
|
marity_test(:marity_test)
|
||||||
marity_test(:p)
|
marity_test(:p)
|
||||||
|
|
||||||
lambda(&method(:assert)).call(true)
|
get_block{|a,n| assert(a,n)}.call(true, "marity")
|
||||||
lambda(&get_block{|a,n| assert(a,n)}).call(true, "marity")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def foo
|
def foo
|
||||||
|
@ -74,6 +74,12 @@ class TestLambdaParameters < Test::Unit::TestCase
|
|||||||
assert_raise(ArgumentError, bug9605) {proc(&plus).call [1,2]}
|
assert_raise(ArgumentError, bug9605) {proc(&plus).call [1,2]}
|
||||||
end
|
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)
|
def pass_along(&block)
|
||||||
lambda(&block)
|
lambda(&block)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user