From 93bdff5589b5dcd60f4b5e98e0c6af9ad6af8ac5 Mon Sep 17 00:00:00 2001 From: zakuro Date: Tue, 23 Nov 2021 14:30:54 +0900 Subject: [PATCH] fmt: remove unnecessary paren in assert stmt (#12546) --- vlib/v/fmt/fmt.v | 12 ++++-------- vlib/v/fmt/tests/asserts_expected.vv | 1 + vlib/v/fmt/tests/asserts_input.vv | 3 ++- vlib/v/gen/js/tests/testdata/match.v | 9 ++++++--- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 27833df5ac..168361f0c9 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -711,15 +711,11 @@ fn expr_is_single_line(expr ast.Expr) bool { pub fn (mut f Fmt) assert_stmt(node ast.AssertStmt) { f.write('assert ') - if node.expr is ast.ParExpr { - if node.expr.expr is ast.InfixExpr { - infix := node.expr.expr - f.expr(infix) - f.writeln('') - return - } + mut expr := node.expr + for expr is ast.ParExpr { + expr = (expr as ast.ParExpr).expr } - f.expr(node.expr) + f.expr(expr) f.writeln('') } diff --git a/vlib/v/fmt/tests/asserts_expected.vv b/vlib/v/fmt/tests/asserts_expected.vv index 08dd71ab77..3100ae3696 100644 --- a/vlib/v/fmt/tests/asserts_expected.vv +++ b/vlib/v/fmt/tests/asserts_expected.vv @@ -2,4 +2,5 @@ fn f() { assert 0 == 0 assert 0 < 1 assert (1 + 2) == 3 + assert true } diff --git a/vlib/v/fmt/tests/asserts_input.vv b/vlib/v/fmt/tests/asserts_input.vv index ae2a01a791..6223c7f6a5 100644 --- a/vlib/v/fmt/tests/asserts_input.vv +++ b/vlib/v/fmt/tests/asserts_input.vv @@ -1,5 +1,6 @@ fn f() { assert (0 == 0) assert (0 < 1) - assert ((1 + 2) == 3) + assert (((((1 + 2) == 3)))) + assert (((true))) } diff --git a/vlib/v/gen/js/tests/testdata/match.v b/vlib/v/gen/js/tests/testdata/match.v index 78e135df15..6402f43aaf 100644 --- a/vlib/v/gen/js/tests/testdata/match.v +++ b/vlib/v/gen/js/tests/testdata/match.v @@ -25,16 +25,19 @@ fn match_vec(v Vec) { fn match_classic_num() { match 42 { 0 { - assert (false) + assert false + (false) } 1 { - assert (false) + assert false + (false) } 42 { println('life') } else { - assert (false) + assert false + (false) } } }