mirror of
https://github.com/vlang/v.git
synced 2025-09-18 11:56:57 -04:00
parent
1a145bfff3
commit
3af35eef14
@ -367,8 +367,9 @@ fn (mut c Checker) check_noreturn_fn_decl(mut node ast.FnDecl) {
|
|||||||
if uses_return_stmt(node.stmts) {
|
if uses_return_stmt(node.stmts) {
|
||||||
c.error('[noreturn] functions cannot use return statements', node.pos)
|
c.error('[noreturn] functions cannot use return statements', node.pos)
|
||||||
}
|
}
|
||||||
if node.stmts.len != 0 {
|
mut pos := node.pos
|
||||||
mut is_valid_end_of_noreturn_fn := false
|
mut is_valid_end_of_noreturn_fn := false
|
||||||
|
if node.stmts.len != 0 {
|
||||||
last_stmt := node.stmts.last()
|
last_stmt := node.stmts.last()
|
||||||
match last_stmt {
|
match last_stmt {
|
||||||
ast.ExprStmt {
|
ast.ExprStmt {
|
||||||
@ -391,11 +392,13 @@ fn (mut c Checker) check_noreturn_fn_decl(mut node ast.FnDecl) {
|
|||||||
else {}
|
else {}
|
||||||
}
|
}
|
||||||
if !is_valid_end_of_noreturn_fn {
|
if !is_valid_end_of_noreturn_fn {
|
||||||
c.error('@[noreturn] functions should end with a call to another @[noreturn] function, or with an infinite `for {}` loop',
|
pos = last_stmt.pos
|
||||||
last_stmt.pos)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !is_valid_end_of_noreturn_fn {
|
||||||
|
c.error('@[noreturn] functions should end with a call to another @[noreturn] function, or with an infinite `for {}` loop',
|
||||||
|
pos)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn uses_return_stmt(stmts []ast.Stmt) bool {
|
fn uses_return_stmt(stmts []ast.Stmt) bool {
|
||||||
|
5
vlib/v/checker/tests/empty_fn_noreturn_err.out
Normal file
5
vlib/v/checker/tests/empty_fn_noreturn_err.out
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
vlib/v/checker/tests/empty_fn_noreturn_err.vv:2:1: error: @[noreturn] functions should end with a call to another @[noreturn] function, or with an infinite `for {}` loop
|
||||||
|
1 | @[noreturn]
|
||||||
|
2 | fn f() {
|
||||||
|
| ~~~~~~
|
||||||
|
3 | }
|
3
vlib/v/checker/tests/empty_fn_noreturn_err.vv
Normal file
3
vlib/v/checker/tests/empty_fn_noreturn_err.vv
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
@[noreturn]
|
||||||
|
fn f() {
|
||||||
|
}
|
@ -21,6 +21,7 @@ fn test2(arg []string) {}
|
|||||||
|
|
||||||
@[noreturn]
|
@[noreturn]
|
||||||
fn test3(a reflection.Function) {
|
fn test3(a reflection.Function) {
|
||||||
|
panic('foo')
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_module_existing() {
|
fn test_module_existing() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user