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

checker: check missing return values in functions (#5803)

This commit is contained in:
yuyi 2020-07-11 22:30:49 +08:00 committed by GitHub
parent 37d739684c
commit 9b4c81e85f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 2 deletions

View File

@ -3060,7 +3060,7 @@ fn (c &Checker) fetch_and_verify_orm_fields(info table.Struct, pos token.Positio
}
fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
c.returns = true
c.returns = false
if node.is_generic && c.cur_generic_type == 0 { // need the cur_generic_type check to avoid inf. recursion
// loop thru each generic type and generate a function
for gen_type in c.table.fn_gen_types[node.name] {
@ -3150,7 +3150,7 @@ fn has_top_return(stmts []ast.Stmt) bool {
if stmts.filter(it is ast.Return).len > 0 {
return true
}
mut has_unsafe_return := false
mut has_unsafe_return := false
for _, stmt in stmts {
if stmt is ast.UnsafeStmt {
for ustmt in stmt.stmts {

View File

@ -0,0 +1,5 @@
vlib/v/checker/tests/function_missing_return_type.v:1:1: error: missing return at end of function `h`
1 | fn h() int {
| ~~~~~~~~~~
2 | }
3 |

View File

@ -0,0 +1,7 @@
fn h() int {
}
fn main() {
d := h()
println('$d')
}