diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 1e3eb79caf..00a119225b 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -3410,8 +3410,8 @@ pub fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type { return ast.void_type } node.expr_type = typ - if node.expr_type.has_flag(.optional) && !((node.expr is ast.Ident - && (node.expr as ast.Ident).kind == .constant)) { + if node.expr_type.has_flag(.optional) && !(node.expr is ast.Ident + && (node.expr as ast.Ident).kind == .constant) { c.error('cannot access fields of an optional, handle the error with `or {...}` or propagate it with `?`', node.pos) } @@ -5435,6 +5435,9 @@ pub fn (mut c Checker) expr(node ast.Expr) ast.Type { // return node.typ // } ast.ParExpr { + if node.expr is ast.ParExpr { + c.warn('redundant parentheses are used', node.pos) + } return c.expr(node.expr) } ast.RangeExpr { @@ -7316,7 +7319,7 @@ pub fn (mut c Checker) index_expr(mut node ast.IndexExpr) ast.Type { if node.left.obj is ast.Var { v := node.left.obj as ast.Var // `mut param []T` function parameter - is_ok = ((v.is_mut && v.is_arg)) && !typ.deref().is_ptr() + is_ok = v.is_mut && v.is_arg && !typ.deref().is_ptr() } } if !is_ok && !c.pref.translated { diff --git a/vlib/v/checker/tests/redundant_parentheses_warning.out b/vlib/v/checker/tests/redundant_parentheses_warning.out new file mode 100644 index 0000000000..a9465b61d1 --- /dev/null +++ b/vlib/v/checker/tests/redundant_parentheses_warning.out @@ -0,0 +1,7 @@ +vlib/v/checker/tests/redundant_parentheses_warning.vv:3:7: error: redundant parentheses are used + 1 | fn main() { + 2 | a := 2 + 3 | b := ((a + 2)) + | ~~~~~~~~~ + 4 | println(b) + 5 | } diff --git a/vlib/v/checker/tests/redundant_parentheses_warning.vv b/vlib/v/checker/tests/redundant_parentheses_warning.vv new file mode 100644 index 0000000000..df64e041ca --- /dev/null +++ b/vlib/v/checker/tests/redundant_parentheses_warning.vv @@ -0,0 +1,5 @@ +fn main() { + a := 2 + b := ((a + 2)) + println(b) +}