fmt: write empty or blocks the same as empty fn bodies, empty structs, etc (#9136)

pull/9168/head
Lukas Neubert 2021-03-06 20:04:51 +01:00 committed by GitHub
parent 7a9d9f1e78
commit fdcfe397d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 48 additions and 38 deletions

View File

@ -850,7 +850,11 @@ pub fn (mut f Fmt) or_expr(node ast.OrExpr) {
.absent {}
.block {
if node.stmts.len == 0 {
f.write(' or { }')
f.write(' or {')
if node.pos.line_nr != node.pos.last_line {
f.writeln('')
}
f.write('}')
return
} else if node.stmts.len == 1 && stmt_is_single_line(node.stmts[0]) {
// the control stmts (return/break/continue...) print a newline inside them,

View File

@ -1,3 +1,9 @@
fn main() {
empty_or_block() or {}
empty_or_block() or {
}
}
fn fn_with_or() int {
fn_with_optional() or { return 10 }
return 20