diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index f5b35effa1..519c6ea13b 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -794,10 +794,12 @@ fn (mut b Builder) cc_linux_cross() { if b.pref.show_cc { println(cc_cmd) } - cc_res := os.exec(cc_cmd) or { os.Result{ - exit_code: 1 - output: 'no `cc` command found' - } } + cc_res := os.exec(cc_cmd) or { + os.Result{ + exit_code: 1 + output: 'no `cc` command found' + } + } if cc_res.exit_code != 0 { println('Cross compilation for Linux failed (first step, cc). Make sure you have clang installed.') verror(cc_res.output) diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 27ee12e494..a6508551bb 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -459,11 +459,10 @@ pub fn (mut f Fmt) stmt(node ast.Stmt) { } fn stmt_is_single_line(stmt ast.Stmt) bool { - match stmt { - ast.ExprStmt { return expr_is_single_line(stmt.expr) } - ast.Return { return true } - ast.AssignStmt { return true } - else { return false } + return match stmt { + ast.ExprStmt, ast.AssertStmt { expr_is_single_line(stmt.expr) } + ast.Return, ast.AssignStmt, ast.BranchStmt { true } + else { false } } } @@ -1065,7 +1064,7 @@ pub fn (mut f Fmt) or_expr(node ast.OrExpr) { if node.stmts.len == 0 { f.write(' or { }') return - } else if node.stmts.len == 1 { + } else if node.stmts.len == 1 && stmt_is_single_line(node.stmts[0]) { // the control stmts (return/break/continue...) print a newline inside them, // so, since this'll all be on one line, trim any possible whitespace str := f.stmt_str(node.stmts[0]).trim_space() diff --git a/vlib/v/fmt/tests/or_keep.vv b/vlib/v/fmt/tests/or_keep.vv index 063408a8d2..67db2f08db 100644 --- a/vlib/v/fmt/tests/or_keep.vv +++ b/vlib/v/fmt/tests/or_keep.vv @@ -18,3 +18,11 @@ fn unwrapped_single_line_if() { println('Another stmt') } } + +fn or_with_one_multi_line_stmt() { + b := or_func() or { + MyStruct{ + val: 'xyz' + } + } +} diff --git a/vlib/v/fmt/tests/stmt_keep.vv b/vlib/v/fmt/tests/stmt_keep.vv new file mode 100644 index 0000000000..1dcb23d39b --- /dev/null +++ b/vlib/v/fmt/tests/stmt_keep.vv @@ -0,0 +1,8 @@ +fn single_line_stmts() { + // Wouldn't be the or-block's stmt be single line, the block would be written as multi line + foo() or { assert false } + for { + foo() or { break } + } + foo() or { return } +}