From 26b0e7fd348a514c21c68bcdf960c36bb912886b Mon Sep 17 00:00:00 2001 From: yuyi Date: Thu, 21 Apr 2022 23:20:32 +0800 Subject: [PATCH] fmt: remove extra parentheses (#14125) --- vlib/v/fmt/fmt.v | 6 +++++- vlib/v/fmt/tests/extra_par_expr_expected.vv | 6 ++++++ vlib/v/fmt/tests/extra_par_expr_input.vv | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 vlib/v/fmt/tests/extra_par_expr_expected.vv create mode 100644 vlib/v/fmt/tests/extra_par_expr_input.vv diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 5502b2d62c..c19e4a3f55 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -2315,7 +2315,11 @@ pub fn (mut f Fmt) par_expr(node ast.ParExpr) { f.par_level++ f.write('(') } - f.expr(node.expr) + mut expr := node.expr + for mut expr is ast.ParExpr { + expr = expr.expr + } + f.expr(expr) if requires_paren { f.par_level-- f.write(')') diff --git a/vlib/v/fmt/tests/extra_par_expr_expected.vv b/vlib/v/fmt/tests/extra_par_expr_expected.vv new file mode 100644 index 0000000000..3c953d7586 --- /dev/null +++ b/vlib/v/fmt/tests/extra_par_expr_expected.vv @@ -0,0 +1,6 @@ +fn main() { + _, _ := (22 > 11), (43 > 22) + _ := (10 + 11) + _ := (11 * 2) + _ := (11 * 2) +} diff --git a/vlib/v/fmt/tests/extra_par_expr_input.vv b/vlib/v/fmt/tests/extra_par_expr_input.vv new file mode 100644 index 0000000000..449071e3d1 --- /dev/null +++ b/vlib/v/fmt/tests/extra_par_expr_input.vv @@ -0,0 +1,6 @@ +fn main() { + _, _ := (((22 > 11))), (43 > 22) + _ := ((10 + 11)) + _ := ((((((11 * 2)))))) + _ := ((11 * 2)) +}