mirror of
https://github.com/vlang/v.git
synced 2025-09-15 07:22:27 +03:00
checker: prohibit casting void
(#10690)
This commit is contained in:
parent
6436d9a827
commit
806d6172cb
5 changed files with 11 additions and 2 deletions
|
@ -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)',
|
||||||
|
|
4
vlib/v/checker/tests/cast_void.out
Normal file
4
vlib/v/checker/tests/cast_void.out
Normal file
|
@ -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)
|
2
vlib/v/checker/tests/cast_void.vv
Normal file
2
vlib/v/checker/tests/cast_void.vv
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
num := int(print(''))
|
||||||
|
println(num)
|
Loading…
Add table
Add a link
Reference in a new issue