Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checker: check expr evaluated but not used (fix #21436) #21816

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
change error to warn and change test for it
yuyi98 committed Jul 7, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit ad952abdc3265a98f3a6d2886272702fb48af2ea
2 changes: 1 addition & 1 deletion vlib/v/checker/checker.v
Original file line number Diff line number Diff line change
@@ -2222,7 +2222,7 @@ fn (mut c Checker) block(mut node ast.Block) {
if node.stmts.len > 0 && node.stmts.last() is ast.ExprStmt {
last_stmt := node.stmts.last() as ast.ExprStmt
if last_stmt.expr !in [ast.CallExpr, ast.IfExpr, ast.MatchExpr, ast.InfixExpr] {
c.error('expression evaluated but not used', node.stmts.last().pos)
c.warn('expression evaluated but not used', node.stmts.last().pos)
}
}
c.stmts(mut node.stmts)
13 changes: 7 additions & 6 deletions vlib/v/checker/tests/expr_evaluated_but_not_used.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
vlib/v/checker/tests/expr_evaluated_but_not_used.vv:2:3: error: expression evaluated but not used
1 | fn main() {
2 | {1, 2, 3, 4}
| ^
3 | println('works')
4 | }
vlib/v/checker/tests/expr_evaluated_but_not_used.vv:7:3: warning: expression evaluated but not used
5 | println(3)
6 | println(4)
7 | 5
| ^
8 | }
9 | println('works')
8 changes: 7 additions & 1 deletion vlib/v/checker/tests/expr_evaluated_but_not_used.vv
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
fn main() {
{1, 2, 3, 4}
{
println(1)
println(2)
println(3)
println(4)
5
}
println('works')
}