diff --git a/vlib/v/checker/return.v b/vlib/v/checker/return.v index 09fc9b05ab..14c87283a1 100644 --- a/vlib/v/checker/return.v +++ b/vlib/v/checker/return.v @@ -359,6 +359,10 @@ fn has_top_return(stmts []ast.Stmt) bool { if stmt.expr.method_name == 'compile_error' { return true } + } else if stmt.expr is ast.LockExpr { + if has_top_return(stmt.expr.stmts) { + return true + } } } else {} diff --git a/vlib/v/checker/tests/lockexpr_missing_return_err.out b/vlib/v/checker/tests/lockexpr_missing_return_err.out new file mode 100644 index 0000000000..68607d4978 --- /dev/null +++ b/vlib/v/checker/tests/lockexpr_missing_return_err.out @@ -0,0 +1,7 @@ +vlib/v/checker/tests/lockexpr_missing_return_err.vv:4:1: error: missing return at end of function `baz` + 2 | } + 3 | + 4 | fn baz(shared foo Foo) int { + | ~~~~~~~~~~~~~~~~~~~~~~~~~~ + 5 | lock foo { + 6 | } diff --git a/vlib/v/checker/tests/lockexpr_missing_return_err.vv b/vlib/v/checker/tests/lockexpr_missing_return_err.vv new file mode 100644 index 0000000000..3527886ce9 --- /dev/null +++ b/vlib/v/checker/tests/lockexpr_missing_return_err.vv @@ -0,0 +1,18 @@ +struct Foo { +} + +fn baz(shared foo Foo) int { + lock foo { + } +} + +fn bar(shared foo Foo) int { + lock foo { + return 1 + } +} + +fn main() { + shared foo := Foo{} + bar(shared foo) +}