checker: prohibit casting `void` (#10690)
							parent
							
								
									6436d9a827
								
							
						
					
					
						commit
						806d6172cb
					
				|  | @ -343,7 +343,7 @@ fn C.closesocket(int) int | ||||||
| 
 | 
 | ||||||
| fn C.vschannel_init(&C.TlsContext) | fn C.vschannel_init(&C.TlsContext) | ||||||
| 
 | 
 | ||||||
| fn C.request(&C.TlsContext, int, &u16, &byte, &&byte) | fn C.request(&C.TlsContext, int, &u16, &byte, &&byte) int | ||||||
| 
 | 
 | ||||||
| fn C.vschannel_cleanup(&C.TlsContext) | fn C.vschannel_cleanup(&C.TlsContext) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -18,7 +18,7 @@ fn (req &Request) ssl_do(port int, method Method, host_name string, path string) | ||||||
| 	$if trace_http_request ? { | 	$if trace_http_request ? { | ||||||
| 		eprintln('> $sdata') | 		eprintln('> $sdata') | ||||||
| 	} | 	} | ||||||
| 	length := int(C.request(&ctx, port, addr.to_wide(), sdata.str, &buff)) | 	length := C.request(&ctx, port, addr.to_wide(), sdata.str, &buff) | ||||||
| 	C.vschannel_cleanup(&ctx) | 	C.vschannel_cleanup(&ctx) | ||||||
| 	response_text := unsafe { buff.vstring_with_len(length) } | 	response_text := unsafe { buff.vstring_with_len(length) } | ||||||
| 	$if trace_http_response ? { | 	$if trace_http_response ? { | ||||||
|  |  | ||||||
|  | @ -5114,6 +5114,9 @@ pub fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type { | ||||||
| 	} | 	} | ||||||
| 	n_e_t_idx := node.expr_type.idx() | 	n_e_t_idx := node.expr_type.idx() | ||||||
| 	expr_is_ptr := node.expr_type.is_ptr() || n_e_t_idx in ast.pointer_type_idxs | 	expr_is_ptr := node.expr_type.is_ptr() || n_e_t_idx in ast.pointer_type_idxs | ||||||
|  | 	if node.expr_type == ast.void_type { | ||||||
|  | 		c.error('expression does not return a value so it cannot be casted', node.expr.position()) | ||||||
|  | 	} | ||||||
| 	if expr_is_ptr && to_type_sym.kind == .string && !node.in_prexpr { | 	if expr_is_ptr && to_type_sym.kind == .string && !node.in_prexpr { | ||||||
| 		if node.has_arg { | 		if node.has_arg { | ||||||
| 			c.warn('to convert a C string buffer pointer to a V string, use x.vstring_with_len(len) instead of string(x,len)', | 			c.warn('to convert a C string buffer pointer to a V string, use x.vstring_with_len(len) instead of string(x,len)', | ||||||
|  |  | ||||||
|  | @ -0,0 +1,4 @@ | ||||||
|  | vlib/v/checker/tests/cast_void.vv:1:12: error: expression does not return a value so it cannot be casted | ||||||
|  |     1 | num := int(print('')) | ||||||
|  |       |            ~~~~~~~~~ | ||||||
|  |     2 | println(num) | ||||||
|  | @ -0,0 +1,2 @@ | ||||||
|  | num := int(print('')) | ||||||
|  | println(num) | ||||||
		Loading…
	
		Reference in New Issue