1
0
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:
Swastik Baranwal 2023-04-07 10:10:11 +05:30 committed by GitHub
parent bb280121e3
commit 65abfa8219
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 0 deletions

View File

@ -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) { if method := c.table.find_method(unwrapped_left_sym, method_name) {
node.receiver_type = method.receiver_type node.receiver_type = method.receiver_type
} }
node.return_type = ast.void_type
} }
return node.return_type return node.return_type
} }

View 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 | }

View File

@ -0,0 +1,5 @@
fn main() {
a := []string{}
println(a.delete(0))
println('${a.delete(0)}')
}