1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

v.checker: check fn returning void type (fix #12076) (#12078)

This commit is contained in:
yuyi 2021-10-07 02:04:33 +08:00 committed by GitHub
parent 5f736dd768
commit 0d53705776
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View File

@ -3706,6 +3706,9 @@ pub fn (mut c Checker) return_stmt(mut node ast.Return) {
mut got_types := []ast.Type{}
for expr in node.exprs {
typ := c.expr(expr)
if typ == ast.void_type {
c.error('`$expr` used as value', node.pos)
}
// Unpack multi return types
sym := c.table.get_type_symbol(typ)
if sym.kind == .multi_return {

View File

@ -0,0 +1,6 @@
vlib/v/checker/tests/return_void_type_err.vv:2:2: error: `println(msg)` used as value
1 | fn hello(msg string) ? {
2 | return println(msg)
| ~~~~~~~~~~~~~~~~~~~
3 | }
4 |

View File

@ -0,0 +1,7 @@
fn hello(msg string) ? {
return println(msg)
}
fn main() {
hello('test') ?
}