checker: check for optional argument in dump() (#14316)
							parent
							
								
									634796ae42
								
							
						
					
					
						commit
						3091f31019
					
				| 
						 | 
				
			
			@ -2670,6 +2670,7 @@ pub fn (mut c Checker) expr(node_ ast.Expr) ast.Type {
 | 
			
		|||
		}
 | 
			
		||||
		ast.DumpExpr {
 | 
			
		||||
			node.expr_type = c.expr(node.expr)
 | 
			
		||||
			c.check_expr_opt_call(node.expr, node.expr_type)
 | 
			
		||||
			etidx := node.expr_type.idx()
 | 
			
		||||
			if etidx == ast.void_type_idx {
 | 
			
		||||
				c.error('dump expression can not be void', node.expr.pos())
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,6 @@
 | 
			
		|||
vlib/v/checker/tests/optional_in_dump_err.vv:10:7: error: create() returns an option, so it should have either an `or {}` block, or `?` at the end
 | 
			
		||||
    8 |
 | 
			
		||||
    9 | fn main() {
 | 
			
		||||
   10 |     dump(create())
 | 
			
		||||
      |          ~~~~~~~~
 | 
			
		||||
   11 | }
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,11 @@
 | 
			
		|||
struct AStruct {
 | 
			
		||||
	field1 int
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn create() ?AStruct {
 | 
			
		||||
	return AStruct{123}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn main() {
 | 
			
		||||
	dump(create())
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue