Skip to content

Commit

Permalink
checker: cleanup check_non_expr_branch_last_stmt (vlang#23330)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp authored Jan 1, 2025
1 parent c786482 commit 734bb00
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions vlib/v/checker/if.v
Original file line number Diff line number Diff line change
Expand Up @@ -690,14 +690,12 @@ fn (mut c Checker) smartcast_if_conds(mut node ast.Expr, mut scope ast.Scope, co
}

fn (mut c Checker) check_non_expr_branch_last_stmt(stmts []ast.Stmt) {
if stmts.len > 0 {
last_stmt := stmts.last()
if last_stmt is ast.ExprStmt {
if last_stmt.expr is ast.InfixExpr {
if last_stmt.expr.op !in [.left_shift, .right_shift, .unsigned_right_shift, .arrow] {
c.error('expression evaluated but not used', last_stmt.pos)
}
}
}
if stmts.len == 0 {
return
}
last_stmt := stmts.last()
if last_stmt is ast.ExprStmt && (last_stmt.expr is ast.InfixExpr
&& last_stmt.expr.op !in [.left_shift, .right_shift, .unsigned_right_shift, .arrow]) {
c.error('expression evaluated but not used', last_stmt.pos)
}
}

0 comments on commit 734bb00

Please sign in to comment.