From 345868853e120561c89734ff109afbd425788c70 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 14 Apr 2021 19:55:26 +0300 Subject: [PATCH] checker: change wording of the error message for complex boolean expressions --- vlib/v/checker/checker.v | 6 +++--- vlib/v/checker/tests/infix_err.out | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 1b1008c4db..c6486a6e12 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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 { 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 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) } } } diff --git a/vlib/v/checker/tests/infix_err.out b/vlib/v/checker/tests/infix_err.out index abff773328..363716913b 100644 --- a/vlib/v/checker/tests/infix_err.out +++ b/vlib/v/checker/tests/infix_err.out @@ -61,22 +61,21 @@ vlib/v/checker/tests/infix_err.vv:18:13: error: right operand for `||` is not a | ^ 19 | 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 | 20 | // boolean expressions 21 | _ = 1 == 1 && 2 == 2 || 3 == 3 | ~~ 22 | _ = 1 == 1 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 22 | _ = 1 == 1 23 | && 2 == 2 || 3 == 3 | ~~ 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 23 | && 2 == 2 || 3 == 3 24 | && 4 == 4 | ~~ -