From 0a7fb346137faf097961b212393d5a1ddc58a788 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 18 Sep 2021 13:42:46 +0300 Subject: [PATCH] checker: simplify noreturn.v --- vlib/v/checker/noreturn.v | 47 ++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/vlib/v/checker/noreturn.v b/vlib/v/checker/noreturn.v index ca4a2883f0..aaf0986049 100644 --- a/vlib/v/checker/noreturn.v +++ b/vlib/v/checker/noreturn.v @@ -9,38 +9,39 @@ fn (mut c Checker) check_noreturn_fn_decl(mut node ast.FnDecl) { if node.no_body { return } + if node.return_type != ast.void_type { + c.error('[noreturn] functions cannot have return types', node.pos) + } if uses_return_stmt(node.stmts) { c.error('[noreturn] functions cannot use return statements', node.pos) } - if node.return_type != ast.void_type { - c.error('[noreturn] functions cannot have return types', node.pos) - } else { - if node.stmts.len != 0 { - mut is_valid_end_of_noreturn_fn := false - last_stmt := node.stmts.last() - match last_stmt { - ast.ExprStmt { - if last_stmt.expr is ast.CallExpr { - if last_stmt.expr.should_be_skipped { - c.error('[noreturn] functions cannot end with a skippable `[if ..]` call', - last_stmt.pos) - } - if last_stmt.expr.is_noreturn { - is_valid_end_of_noreturn_fn = true - } + if node.stmts.len != 0 { + mut is_valid_end_of_noreturn_fn := false + last_stmt := node.stmts.last() + match last_stmt { + ast.ExprStmt { + if last_stmt.expr is ast.CallExpr { + if last_stmt.expr.should_be_skipped { + c.error('[noreturn] functions cannot end with a skippable `[if ..]` call', + last_stmt.pos) + return } - } - ast.ForStmt { - if last_stmt.is_inf && last_stmt.stmts.len == 0 { + if last_stmt.expr.is_noreturn { is_valid_end_of_noreturn_fn = true } } - else {} } - 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', - last_stmt.pos) + ast.ForStmt { + if last_stmt.is_inf && last_stmt.stmts.len == 0 { + is_valid_end_of_noreturn_fn = true + } } + else {} + } + 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', + last_stmt.pos) + return } } }