Skip to content

Commit

Permalink
v.markused: process the init statements in for init; cond; inc { too
Browse files Browse the repository at this point in the history
  • Loading branch information
spytheman committed Nov 18, 2024
1 parent 2ba1271 commit 9551580
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
15 changes: 12 additions & 3 deletions vlib/v/markused/walker.v
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,15 @@ pub fn (mut w Walker) stmt(node_ ast.Stmt) {
w.fn_decl(mut node)
}
ast.ForCStmt {
w.expr(node.cond)
w.stmt(node.inc)
if node.has_init {
w.stmt(node.init)
}
if node.has_cond {
w.expr(node.cond)
}
if node.has_inc {
w.stmt(node.inc)
}
w.stmts(node.stmts)
}
ast.ForInStmt {
Expand All @@ -179,7 +186,9 @@ pub fn (mut w Walker) stmt(node_ ast.Stmt) {
}
}
ast.ForStmt {
w.expr(node.cond)
if !node.is_inf {
w.expr(node.cond)
}
w.stmts(node.stmts)
}
ast.Return {
Expand Down
5 changes: 5 additions & 0 deletions vlib/v/tests/skip_unused/for_c_stmt.run.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ok
12
13
14
ok
5 changes: 5 additions & 0 deletions vlib/v/tests/skip_unused/for_c_stmt.skip_unused.run.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ok
12
13
14
ok
10 changes: 10 additions & 0 deletions vlib/v/tests/skip_unused/for_c_stmt.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const abc = 12

fn main() {
println('ok')
for x := abc; x<15;x++ {
println(x)
}
println('ok')
}

0 comments on commit 9551580

Please sign in to comment.