1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: warn instead of error, for unnecessary brackets on if/match (#18117)

This commit is contained in:
squidink7 2023-05-06 20:47:45 +09:30 committed by GitHub
parent 134e781965
commit 787d774523
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 6 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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()) {

View File

@ -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) {