fmt: remove unnecessary paren in assert stmt (#12546)

pull/12541/head
zakuro 2021-11-23 14:30:54 +09:00 committed by GitHub
parent fbe2b5cb58
commit 93bdff5589
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 12 deletions

View File

@ -711,15 +711,11 @@ fn expr_is_single_line(expr ast.Expr) bool {
pub fn (mut f Fmt) assert_stmt(node ast.AssertStmt) { pub fn (mut f Fmt) assert_stmt(node ast.AssertStmt) {
f.write('assert ') f.write('assert ')
if node.expr is ast.ParExpr { mut expr := node.expr
if node.expr.expr is ast.InfixExpr { for expr is ast.ParExpr {
infix := node.expr.expr expr = (expr as ast.ParExpr).expr
f.expr(infix)
f.writeln('')
return
}
} }
f.expr(node.expr) f.expr(expr)
f.writeln('') f.writeln('')
} }

View File

@ -2,4 +2,5 @@ fn f() {
assert 0 == 0 assert 0 == 0
assert 0 < 1 assert 0 < 1
assert (1 + 2) == 3 assert (1 + 2) == 3
assert true
} }

View File

@ -1,5 +1,6 @@
fn f() { fn f() {
assert (0 == 0) assert (0 == 0)
assert (0 < 1) assert (0 < 1)
assert ((1 + 2) == 3) assert (((((1 + 2) == 3))))
assert (((true)))
} }

View File

@ -25,16 +25,19 @@ fn match_vec(v Vec) {
fn match_classic_num() { fn match_classic_num() {
match 42 { match 42 {
0 { 0 {
assert (false) assert false
(false)
} }
1 { 1 {
assert (false) assert false
(false)
} }
42 { 42 {
println('life') println('life')
} }
else { else {
assert (false) assert false
(false)
} }
} }
} }