checker: minor cleanup in find_unreachable_statements_after_noreturn_calls() (#13903)

pull/13919/head
yuyi 2022-04-03 16:19:19 +08:00 committed by GitHub
parent 8c55a9ecd3
commit 0497b885dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 11 deletions

View File

@ -158,19 +158,16 @@ pub fn (mut c Checker) return_stmt(mut node ast.Return) {
pub fn (mut c Checker) find_unreachable_statements_after_noreturn_calls(stmts []ast.Stmt) { pub fn (mut c Checker) find_unreachable_statements_after_noreturn_calls(stmts []ast.Stmt) {
mut prev_stmt_was_noreturn_call := false mut prev_stmt_was_noreturn_call := false
for stmt in stmts { for stmt in stmts {
match stmt { if stmt is ast.ExprStmt {
ast.ExprStmt { if stmt.expr is ast.CallExpr {
if stmt.expr is ast.CallExpr { if prev_stmt_was_noreturn_call {
if prev_stmt_was_noreturn_call { c.error('unreachable code after a [noreturn] call', stmt.pos)
c.error('unreachable code after a [noreturn] call', stmt.pos) return
return
}
prev_stmt_was_noreturn_call = stmt.expr.is_noreturn
} }
prev_stmt_was_noreturn_call = stmt.expr.is_noreturn
} }
else { } else {
prev_stmt_was_noreturn_call = false prev_stmt_was_noreturn_call = false
}
} }
} }
} }