diff --git a/vlib/v/markused/walker.v b/vlib/v/markused/walker.v index 8abcc6666e..de28a219e1 100644 --- a/vlib/v/markused/walker.v +++ b/vlib/v/markused/walker.v @@ -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 { @@ -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 { diff --git a/vlib/v/tests/skip_unused/for_c_stmt.run.out b/vlib/v/tests/skip_unused/for_c_stmt.run.out new file mode 100644 index 0000000000..f1a3a7c919 --- /dev/null +++ b/vlib/v/tests/skip_unused/for_c_stmt.run.out @@ -0,0 +1,5 @@ +ok +12 +13 +14 +ok diff --git a/vlib/v/tests/skip_unused/for_c_stmt.skip_unused.run.out b/vlib/v/tests/skip_unused/for_c_stmt.skip_unused.run.out new file mode 100644 index 0000000000..f1a3a7c919 --- /dev/null +++ b/vlib/v/tests/skip_unused/for_c_stmt.skip_unused.run.out @@ -0,0 +1,5 @@ +ok +12 +13 +14 +ok diff --git a/vlib/v/tests/skip_unused/for_c_stmt.vv b/vlib/v/tests/skip_unused/for_c_stmt.vv new file mode 100644 index 0000000000..c45363f52b --- /dev/null +++ b/vlib/v/tests/skip_unused/for_c_stmt.vv @@ -0,0 +1,10 @@ +const abc = 12 + +fn main() { + println('ok') + for x := abc; x<15;x++ { + println(x) + } + println('ok') +} +