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:
parent
134e781965
commit
787d774523
@ -52,7 +52,7 @@ fn (mut c Checker) if_expr(mut node ast.IfExpr) ast.Type {
|
|||||||
for i in 0 .. node.branches.len {
|
for i in 0 .. node.branches.len {
|
||||||
mut branch := node.branches[i]
|
mut branch := node.branches[i]
|
||||||
if branch.cond is ast.ParExpr && !c.pref.translated && !c.file.is_translated {
|
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)
|
branch.pos)
|
||||||
}
|
}
|
||||||
if !node.has_else || i < node.branches.len - 1 {
|
if !node.has_else || i < node.branches.len - 1 {
|
||||||
|
@ -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.is_expr = c.expected_type != ast.void_type
|
||||||
node.expected_type = c.expected_type
|
node.expected_type = c.expected_type
|
||||||
if mut node.cond is ast.ParExpr && !c.pref.translated && !c.file.is_translated {
|
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)
|
node.cond.pos)
|
||||||
}
|
}
|
||||||
if node.is_expr {
|
if node.is_expr {
|
||||||
|
@ -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 |
|
12 |
|
||||||
13 | fn bar() bool {
|
13 | fn bar() bool {
|
||||||
14 | return match (foo()) {
|
14 | return match (foo()) {
|
||||||
|
@ -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() {
|
1 | fn main() {
|
||||||
2 | if (1 == 1) {
|
2 | if (1 == 1) {
|
||||||
| ~~~~~~~~~~~
|
| ~~~~~~~~~~~
|
||||||
3 | println('yeay')
|
3 | println('yeay')
|
||||||
4 | } else if (1 == 2) {
|
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) {
|
2 | if (1 == 1) {
|
||||||
3 | println('yeay')
|
3 | println('yeay')
|
||||||
4 | } else if (1 == 2) {
|
4 | } else if (1 == 2) {
|
||||||
| ~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~
|
||||||
5 | println("oh no :'(")
|
5 | println("oh no :'(")
|
||||||
6 | } else if (1 == 3) {
|
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) {
|
4 | } else if (1 == 2) {
|
||||||
5 | println("oh no :'(")
|
5 | println("oh no :'(")
|
||||||
6 | } else if (1 == 3) {
|
6 | } else if (1 == 3) {
|
||||||
|
Loading…
Reference in New Issue
Block a user