From bbd1027a042f1cd94eafc08ccea6894ece4e60be Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+tobealive@users.noreply.github.com> Date: Wed, 14 Jun 2023 14:05:50 +0200 Subject: [PATCH] fmt: remove all unnecessary parenthesis at once, instead of one pair at a time (#18441) --- vlib/v/fmt/fmt.v | 10 +++++----- vlib/v/fmt/tests/extra_par_expr_expected.vv | 5 +++++ vlib/v/fmt/tests/extra_par_expr_input.vv | 5 +++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 0e38b9c5c1..d45a37f4f5 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -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-- diff --git a/vlib/v/fmt/tests/extra_par_expr_expected.vv b/vlib/v/fmt/tests/extra_par_expr_expected.vv index 3c953d7586..b0e6f762ca 100644 --- a/vlib/v/fmt/tests/extra_par_expr_expected.vv +++ b/vlib/v/fmt/tests/extra_par_expr_expected.vv @@ -1,4 +1,9 @@ fn main() { + x := 3 + _ := &x + _ := &x + _ := &x + _, _ := (22 > 11), (43 > 22) _ := (10 + 11) _ := (11 * 2) diff --git a/vlib/v/fmt/tests/extra_par_expr_input.vv b/vlib/v/fmt/tests/extra_par_expr_input.vv index 449071e3d1..ffcd978b07 100644 --- a/vlib/v/fmt/tests/extra_par_expr_input.vv +++ b/vlib/v/fmt/tests/extra_par_expr_input.vv @@ -1,4 +1,9 @@ fn main() { + x := 3 + _ := &((x)) + _ := &(((x))) + _ := &((((x)))) + _, _ := (((22 > 11))), (43 > 22) _ := ((10 + 11)) _ := ((((((11 * 2))))))