Skip to content

Commit

Permalink
cgen: support inc cond for c style for loop with alias types (#21708)
Browse files Browse the repository at this point in the history
  • Loading branch information
Delta456 committed Jun 22, 2024
1 parent 4302f86 commit 2bb815f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion vlib/v/gen/c/assign.v
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,9 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
g.expr(left)
g.write(' ${extracted_op} ')
g.expr(val)
g.write(';')
if !g.inside_for_c_stmt {
g.write(';')
}
return
} else {
g.write(' = ${styp}_${util.replace_op(extracted_op)}(')
Expand Down
11 changes: 11 additions & 0 deletions vlib/v/tests/alias_assigned_in_increment_part_of_for_c_loop_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type Float = f32

fn test_increment_of_alias_in_for_c_loop() {
min_value := Float(1)
max_value := Float(10)
step := Float(1)
for n := min_value; n <= max_value; n += step {
println('${n}')
assert n > 0.0 && n < 11.0
}
}

0 comments on commit 2bb815f

Please sign in to comment.