Skip to content

Commit abcebfe

Browse files
authored
cgen: fix codegen for for or-block (fix #23625) (#23644)
1 parent 319eb83 commit abcebfe

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

‎vlib/v/gen/c/cgen.v‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,6 +2131,13 @@ fn (mut g Gen) stmts_with_tmp_var(stmts []ast.Stmt, tmp_var string) bool {
21312131
}
21322132
}
21332133
} else {
2134+
if i > 0 && stmt is ast.Return {
2135+
last_stmt := stmts[i - 1]
2136+
if last_stmt is ast.ExprStmt && last_stmt.expr is ast.CallExpr
2137+
&& !g.out.last_n(2).contains(';') {
2138+
g.writeln(';')
2139+
}
2140+
}
21342141
g.stmt(stmt)
21352142
if (g.inside_if_option || g.inside_if_result || g.inside_match_option
21362143
|| g.inside_match_result) && stmt is ast.ExprStmt {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
fn option() ![]int {
2+
return []
3+
}
4+
5+
fn func() {}
6+
7+
fn test_main() {
8+
for _ in option() or {
9+
func()
10+
return
11+
} {
12+
}
13+
assert true
14+
}

0 commit comments

Comments
 (0)