checker: fix missing detection for return in lockexpr stmts (fix #23434) (#23435)

This commit is contained in:
Felipe Pena 2025-01-11 14:27:25 -03:00 committed by GitHub
parent 1c2f1a3504
commit 7aca8b69da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 0 deletions

View File

@ -359,6 +359,10 @@ fn has_top_return(stmts []ast.Stmt) bool {
if stmt.expr.method_name == 'compile_error' { if stmt.expr.method_name == 'compile_error' {
return true return true
} }
} else if stmt.expr is ast.LockExpr {
if has_top_return(stmt.expr.stmts) {
return true
}
} }
} }
else {} else {}

View File

@ -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 | }

View File

@ -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)
}