From 787d774523226b06e38df58610c8419fda40ce06 Mon Sep 17 00:00:00 2001 From: squidink7 <56238661+squidink7@users.noreply.github.com> Date: Sat, 6 May 2023 20:47:45 +0930 Subject: [PATCH] checker: warn instead of error, for unnecessary brackets on if/match (#18117) --- vlib/v/checker/if.v | 2 +- vlib/v/checker/match.v | 2 +- vlib/v/checker/tests/match_cond_with_parenthesis_err.out | 2 +- vlib/v/checker/tests/unnecessary_parenthesis.out | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/vlib/v/checker/if.v b/vlib/v/checker/if.v index e3f8cef98..8c5163e58 100644 --- a/vlib/v/checker/if.v +++ b/vlib/v/checker/if.v @@ -52,7 +52,7 @@ fn (mut c Checker) if_expr(mut node ast.IfExpr) ast.Type { for i in 0 .. node.branches.len { mut branch := node.branches[i] if branch.cond is ast.ParExpr && !c.pref.translated && !c.file.is_translated { - c.error('unnecessary `()` in `${if_kind}` condition, use `${if_kind} expr {` instead of `${if_kind} (expr) {`.', + c.warn('unnecessary `()` in `${if_kind}` condition, use `${if_kind} expr {` instead of `${if_kind} (expr) {`.', branch.pos) } if !node.has_else || i < node.branches.len - 1 { diff --git a/vlib/v/checker/match.v b/vlib/v/checker/match.v index 7b1d5b7c7..6f467f8aa 100644 --- a/vlib/v/checker/match.v +++ b/vlib/v/checker/match.v @@ -9,7 +9,7 @@ fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type { node.is_expr = c.expected_type != ast.void_type node.expected_type = c.expected_type if mut node.cond is ast.ParExpr && !c.pref.translated && !c.file.is_translated { - c.error('unnecessary `()` in `match` condition, use `match expr {` instead of `match (expr) {`.', + c.warn('unnecessary `()` in `match` condition, use `match expr {` instead of `match (expr) {`.', node.cond.pos) } if node.is_expr { diff --git a/vlib/v/checker/tests/match_cond_with_parenthesis_err.out b/vlib/v/checker/tests/match_cond_with_parenthesis_err.out index 5a8f82c94..e8323231f 100644 --- a/vlib/v/checker/tests/match_cond_with_parenthesis_err.out +++ b/vlib/v/checker/tests/match_cond_with_parenthesis_err.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/match_cond_with_parenthesis_err.vv:14:15: error: unnecessary `()` in `match` condition, use `match expr {` instead of `match (expr) {`. +vlib/v/checker/tests/match_cond_with_parenthesis_err.vv:14:15: warning: unnecessary `()` in `match` condition, use `match expr {` instead of `match (expr) {`. 12 | 13 | fn bar() bool { 14 | return match (foo()) { diff --git a/vlib/v/checker/tests/unnecessary_parenthesis.out b/vlib/v/checker/tests/unnecessary_parenthesis.out index eee14f79f..3f1a34036 100644 --- a/vlib/v/checker/tests/unnecessary_parenthesis.out +++ b/vlib/v/checker/tests/unnecessary_parenthesis.out @@ -1,17 +1,17 @@ -vlib/v/checker/tests/unnecessary_parenthesis.vv:2:2: error: unnecessary `()` in `if` condition, use `if expr {` instead of `if (expr) {`. +vlib/v/checker/tests/unnecessary_parenthesis.vv:2:2: warning: unnecessary `()` in `if` condition, use `if expr {` instead of `if (expr) {`. 1 | fn main() { 2 | if (1 == 1) { | ~~~~~~~~~~~ 3 | println('yeay') 4 | } else if (1 == 2) { -vlib/v/checker/tests/unnecessary_parenthesis.vv:4:4: error: unnecessary `()` in `if` condition, use `if expr {` instead of `if (expr) {`. +vlib/v/checker/tests/unnecessary_parenthesis.vv:4:4: warning: unnecessary `()` in `if` condition, use `if expr {` instead of `if (expr) {`. 2 | if (1 == 1) { 3 | println('yeay') 4 | } else if (1 == 2) { | ~~~~~~~~~~~~~~~~ 5 | println("oh no :'(") 6 | } else if (1 == 3) { -vlib/v/checker/tests/unnecessary_parenthesis.vv:6:4: error: unnecessary `()` in `if` condition, use `if expr {` instead of `if (expr) {`. +vlib/v/checker/tests/unnecessary_parenthesis.vv:6:4: warning: unnecessary `()` in `if` condition, use `if expr {` instead of `if (expr) {`. 4 | } else if (1 == 2) { 5 | println("oh no :'(") 6 | } else if (1 == 3) { -- 2.39.5