Skip to content

Commit

Permalink
checker: fix missing detection for return in lockexpr stmts (fix #2…
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp authored Jan 11, 2025
1 parent 1c2f1a3 commit 7aca8b6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions vlib/v/checker/return.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
7 changes: 7 additions & 0 deletions vlib/v/checker/tests/lockexpr_missing_return_err.out
Original file line number Diff line number Diff line change
@@ -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 | }
18 changes: 18 additions & 0 deletions vlib/v/checker/tests/lockexpr_missing_return_err.vv
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 7aca8b6

Please sign in to comment.