diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 9ea7d53d4f..eb5566719d 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -5912,6 +5912,9 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type ast.Ty g.indent-- } else { g.stmts(stmts) + if stmts.len > 0 && stmts[or_block.stmts.len - 1] is ast.ExprStmt { + g.writeln(';') + } } } else if or_block.kind == .propagate { if g.file.mod.name == 'main' && (isnil(g.fn_decl) || g.fn_decl.is_main) { @@ -5942,7 +5945,7 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type ast.Ty } } } - g.write('}') + g.writeln('}') } // `a in [1,2,3]` => `a == 1 || a == 2 || a == 3` diff --git a/vlib/v/tests/for_in_optional_test.v b/vlib/v/tests/for_in_optional_test.v new file mode 100644 index 0000000000..a7052b3e7e --- /dev/null +++ b/vlib/v/tests/for_in_optional_test.v @@ -0,0 +1,8 @@ +import os + +fn test_for_in_optional() { + for d in os.read_lines(@FILE) or { panic('not found') } { + println(d) + } + assert true +}