mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: disallow printing void (#17901)
This commit is contained in:
parent
bb280121e3
commit
65abfa8219
@ -2436,6 +2436,7 @@ fn (mut c Checker) array_builtin_method_call(mut node ast.CallExpr, left_type as
|
||||
if method := c.table.find_method(unwrapped_left_sym, method_name) {
|
||||
node.receiver_type = method.receiver_type
|
||||
}
|
||||
node.return_type = ast.void_type
|
||||
}
|
||||
return node.return_type
|
||||
}
|
||||
|
13
vlib/v/checker/tests/array_delete_print_err.out
Normal file
13
vlib/v/checker/tests/array_delete_print_err.out
Normal file
@ -0,0 +1,13 @@
|
||||
vlib/v/checker/tests/array_delete_print_err.vv:3:2: error: `println` can not print void expressions
|
||||
1 | fn main() {
|
||||
2 | a := []string{}
|
||||
3 | println(a.delete(0))
|
||||
| ~~~~~~~~~~~~~~~~~~~~
|
||||
4 | println('${a.delete(0)}')
|
||||
5 | }
|
||||
vlib/v/checker/tests/array_delete_print_err.vv:4:15: error: expression does not return a value
|
||||
2 | a := []string{}
|
||||
3 | println(a.delete(0))
|
||||
4 | println('${a.delete(0)}')
|
||||
| ~~~~~~~~~
|
||||
5 | }
|
5
vlib/v/checker/tests/array_delete_print_err.vv
Normal file
5
vlib/v/checker/tests/array_delete_print_err.vv
Normal file
@ -0,0 +1,5 @@
|
||||
fn main() {
|
||||
a := []string{}
|
||||
println(a.delete(0))
|
||||
println('${a.delete(0)}')
|
||||
}
|
Loading…
Reference in New Issue
Block a user