mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	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 
				
			
			
			
		
		
					 4 changed files with 20 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -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?
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										13
									
								
								proc.c
									
										
									
									
									
								
							
							
						
						
									
										13
									
								
								proc.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -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();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue