mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: change wording of the error message for complex boolean expressions
This commit is contained in:
parent
7071e8b682
commit
345868853e
@ -1043,11 +1043,11 @@ pub fn (mut c Checker) infix_expr(mut infix_expr ast.InfixExpr) ast.Type {
|
|||||||
if infix_expr.right_type != ast.bool_type_idx {
|
if infix_expr.right_type != ast.bool_type_idx {
|
||||||
c.error('right operand for `$infix_expr.op` is not a boolean', infix_expr.right.position())
|
c.error('right operand for `$infix_expr.op` is not a boolean', infix_expr.right.position())
|
||||||
}
|
}
|
||||||
// use `()` to make the boolean expression clear error
|
|
||||||
// for example: `(a && b) || c` instead of `a && b || c`
|
|
||||||
if mut infix_expr.left is ast.InfixExpr {
|
if mut infix_expr.left is ast.InfixExpr {
|
||||||
if infix_expr.left.op != infix_expr.op && infix_expr.left.op in [.logical_or, .and] {
|
if infix_expr.left.op != infix_expr.op && infix_expr.left.op in [.logical_or, .and] {
|
||||||
c.error('use `()` to make the boolean expression clear', infix_expr.pos)
|
// for example: `(a && b) || c` instead of `a && b || c`
|
||||||
|
c.error('ambiguous boolean expression. use `()` to ensure correct order of operations',
|
||||||
|
infix_expr.pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,22 +61,21 @@ vlib/v/checker/tests/infix_err.vv:18:13: error: right operand for `||` is not a
|
|||||||
| ^
|
| ^
|
||||||
19 |
|
19 |
|
||||||
20 | // boolean expressions
|
20 | // boolean expressions
|
||||||
vlib/v/checker/tests/infix_err.vv:21:22: error: use `()` to make the boolean expression clear
|
vlib/v/checker/tests/infix_err.vv:21:22: error: ambiguous boolean expression. use `()` to ensure correct order of operations
|
||||||
19 |
|
19 |
|
||||||
20 | // boolean expressions
|
20 | // boolean expressions
|
||||||
21 | _ = 1 == 1 && 2 == 2 || 3 == 3
|
21 | _ = 1 == 1 && 2 == 2 || 3 == 3
|
||||||
| ~~
|
| ~~
|
||||||
22 | _ = 1 == 1
|
22 | _ = 1 == 1
|
||||||
23 | && 2 == 2 || 3 == 3
|
23 | && 2 == 2 || 3 == 3
|
||||||
vlib/v/checker/tests/infix_err.vv:23:12: error: use `()` to make the boolean expression clear
|
vlib/v/checker/tests/infix_err.vv:23:12: error: ambiguous boolean expression. use `()` to ensure correct order of operations
|
||||||
21 | _ = 1 == 1 && 2 == 2 || 3 == 3
|
21 | _ = 1 == 1 && 2 == 2 || 3 == 3
|
||||||
22 | _ = 1 == 1
|
22 | _ = 1 == 1
|
||||||
23 | && 2 == 2 || 3 == 3
|
23 | && 2 == 2 || 3 == 3
|
||||||
| ~~
|
| ~~
|
||||||
24 | && 4 == 4
|
24 | && 4 == 4
|
||||||
vlib/v/checker/tests/infix_err.vv:24:2: error: use `()` to make the boolean expression clear
|
vlib/v/checker/tests/infix_err.vv:24:2: error: ambiguous boolean expression. use `()` to ensure correct order of operations
|
||||||
22 | _ = 1 == 1
|
22 | _ = 1 == 1
|
||||||
23 | && 2 == 2 || 3 == 3
|
23 | && 2 == 2 || 3 == 3
|
||||||
24 | && 4 == 4
|
24 | && 4 == 4
|
||||||
| ~~
|
| ~~
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user