checker: check missing return values in functions (#5803)
parent
37d739684c
commit
9b4c81e85f
|
@ -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) {
|
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
|
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
|
// loop thru each generic type and generate a function
|
||||||
for gen_type in c.table.fn_gen_types[node.name] {
|
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 {
|
if stmts.filter(it is ast.Return).len > 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
mut has_unsafe_return := false
|
mut has_unsafe_return := false
|
||||||
for _, stmt in stmts {
|
for _, stmt in stmts {
|
||||||
if stmt is ast.UnsafeStmt {
|
if stmt is ast.UnsafeStmt {
|
||||||
for ustmt in stmt.stmts {
|
for ustmt in stmt.stmts {
|
||||||
|
|
|
@ -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 |
|
|
@ -0,0 +1,7 @@
|
||||||
|
fn h() int {
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
d := h()
|
||||||
|
println('$d')
|
||||||
|
}
|
Loading…
Reference in New Issue