Skip to content

Commit

Permalink
fmt: remove all unnecessary parenthesis at once, instead of one pair …
Browse files Browse the repository at this point in the history
…at a time (#18441)
  • Loading branch information
ttytm authored Jun 14, 2023
1 parent 6806086 commit bbd1027
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
10 changes: 5 additions & 5 deletions vlib/v/fmt/fmt.v
Original file line number Diff line number Diff line change
Expand Up @@ -2599,15 +2599,15 @@ pub fn (mut f Fmt) or_expr(node ast.OrExpr) {
}

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
for mut expr is ast.ParExpr {
expr = expr.expr
}
requires_paren := expr !is ast.Ident
if requires_paren {
f.par_level++
f.write('(')
}
f.expr(expr)
if requires_paren {
f.par_level--
Expand Down
5 changes: 5 additions & 0 deletions vlib/v/fmt/tests/extra_par_expr_expected.vv
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
fn main() {
x := 3
_ := &x
_ := &x
_ := &x

_, _ := (22 > 11), (43 > 22)
_ := (10 + 11)
_ := (11 * 2)
Expand Down
5 changes: 5 additions & 0 deletions vlib/v/fmt/tests/extra_par_expr_input.vv
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
fn main() {
x := 3
_ := &((x))
_ := &(((x)))
_ := &((((x))))

_, _ := (((22 > 11))), (43 > 22)
_ := ((10 + 11))
_ := ((((((11 * 2))))))
Expand Down

0 comments on commit bbd1027

Please sign in to comment.