1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix for (int i = 0; i < 10; i++, a++) { (multiple expressions in the inc part)

This commit is contained in:
Delyan Angelov 2022-06-04 19:51:00 +03:00
parent 82eb495617
commit 3ac3375b43
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 21 additions and 1 deletions

View File

@ -70,7 +70,21 @@ fn (mut g Gen) for_c_stmt(node ast.ForCStmt) {
}
g.write('; ')
if node.has_inc {
g.stmt(node.inc)
mut processed := false
if node.inc is ast.ExprStmt {
if node.inc.expr is ast.ConcatExpr {
for inc_expr_idx, inc_expr in node.inc.expr.vals {
g.expr(inc_expr)
if inc_expr_idx < node.inc.expr.vals.len - 1 {
g.write(', ')
}
}
processed = true
}
}
if !processed {
g.stmt(node.inc)
}
}
g.writeln(') {')
g.is_vlines_enabled = true

View File

@ -0,0 +1,6 @@
fn test_2_expressions_in_same_for_increment_part() {
mut a := 0
for i := 0; i < 10; i++, a++ {
assert a == i
}
}