diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 3a3ddc45a7..bda90c6756 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -1028,30 +1028,28 @@ fn expr_is_single_line(expr ast.Expr) bool { return true } -pub fn (mut f Fmt) or_expr(or_block ast.OrExpr) { - match or_block.kind { +pub fn (mut f Fmt) or_expr(node ast.OrExpr) { + match node.kind { .absent {} .block { - if or_block.stmts.len == 0 { + if node.stmts.len == 0 { f.write(' or { }') - } else if or_block.stmts.len == 1 { + return + } else if node.stmts.len == 1 { // 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(or_block.stmts[0]).trim_space() + str := f.stmt_str(node.stmts[0]).trim_space() single_line := ' or { $str }' if single_line.len + f.line_len <= fmt.max_len.last() { f.write(single_line) - } else { - // if the line would be too long, make it multiline - f.writeln(' or {') - f.stmts(or_block.stmts) - f.write('}') + return } - } else { - f.writeln(' or {') - f.stmts(or_block.stmts) - f.write('}') } + // Make it multiline if the blocks has at least two stmts + // or a single line would be too long + f.writeln(' or {') + f.stmts(node.stmts) + f.write('}') } .propagate { f.write(' ?')