1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

fmt: remove all unnecessary parenthesis at once, instead of one pair at a time (#18441)

This commit is contained in:
Turiiya 2023-06-14 14:05:50 +02:00 committed by GitHub
parent 6806086bf1
commit bbd1027a04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 5 deletions

View File

@ -2599,15 +2599,15 @@ pub fn (mut f Fmt) or_expr(node ast.OrExpr) {
} }
pub fn (mut f Fmt) par_expr(node ast.ParExpr) { pub fn (mut f Fmt) par_expr(node ast.ParExpr) {
requires_paren := node.expr !is ast.Ident
if requires_paren {
f.par_level++
f.write('(')
}
mut expr := node.expr mut expr := node.expr
for mut expr is ast.ParExpr { for mut expr is ast.ParExpr {
expr = expr.expr expr = expr.expr
} }
requires_paren := expr !is ast.Ident
if requires_paren {
f.par_level++
f.write('(')
}
f.expr(expr) f.expr(expr)
if requires_paren { if requires_paren {
f.par_level-- f.par_level--

View File

@ -1,4 +1,9 @@
fn main() { fn main() {
x := 3
_ := &x
_ := &x
_ := &x
_, _ := (22 > 11), (43 > 22) _, _ := (22 > 11), (43 > 22)
_ := (10 + 11) _ := (10 + 11)
_ := (11 * 2) _ := (11 * 2)

View File

@ -1,4 +1,9 @@
fn main() { fn main() {
x := 3
_ := &((x))
_ := &(((x)))
_ := &((((x))))
_, _ := (((22 > 11))), (43 > 22) _, _ := (((22 > 11))), (43 > 22)
_ := ((10 + 11)) _ := ((10 + 11))
_ := ((((((11 * 2)))))) _ := ((((((11 * 2))))))