From a52539702299c2002a72a12f9e99401e5473b4ed Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Wed, 11 Nov 2020 13:11:27 -0800 Subject: [PATCH] checker: improve wording on error messages (#6799) --- vlib/v/checker/checker.v | 6 +++--- vlib/v/checker/tests/optional_method_err.out | 2 +- vlib/v/checker/tests/unexpected_or_propagate.out | 4 ++-- vlib/v/checker/tests/wrong_propagate_ret_type.out | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index f64397d088..af8823d8e3 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -1629,7 +1629,7 @@ pub fn (mut c Checker) check_expr_opt_call(expr ast.Expr, ret_type table.Type) t if expr.return_type.has_flag(.optional) { if expr.or_block.kind == .absent { if ret_type != table.void_type { - c.error('${expr.name}() returns an option, but you missed to add an `or {}` block to it', + c.error('${expr.name}() returns an option but is missing an `or {}` block', expr.pos) } } else { @@ -1643,7 +1643,7 @@ pub fn (mut c Checker) check_expr_opt_call(expr ast.Expr, ret_type table.Type) t c.error('unexpected `or` block, the function `$expr.name` does not return an optional', expr.or_block.pos) } else if expr.or_block.kind == .propagate { - c.error('unexpected `?`, the function `$expr.name`, does not return an optional', + c.error('unexpected `?`, the function `$expr.name` does not return an optional', expr.or_block.pos) } } @@ -1653,7 +1653,7 @@ pub fn (mut c Checker) check_expr_opt_call(expr ast.Expr, ret_type table.Type) t pub fn (mut c Checker) check_or_expr(or_expr ast.OrExpr, ret_type table.Type, expr_return_type table.Type) { if or_expr.kind == .propagate { if !c.cur_fn.return_type.has_flag(.optional) && c.cur_fn.name != 'main.main' { - c.error('to propagate the optional call, `$c.cur_fn.name` must itself return an optional', + c.error('to propagate the optional call, `$c.cur_fn.name` must return an optional', or_expr.pos) } return diff --git a/vlib/v/checker/tests/optional_method_err.out b/vlib/v/checker/tests/optional_method_err.out index 51fdc93ebb..0029014e49 100644 --- a/vlib/v/checker/tests/optional_method_err.out +++ b/vlib/v/checker/tests/optional_method_err.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/optional_method_err.vv:17:10: error: inc_to_limit() returns an option, but you missed to add an `or {}` block to it +vlib/v/checker/tests/optional_method_err.vv:17:10: error: inc_to_limit() returns an option but is missing an `or {}` block 15 | mut a := Abc{} 16 | for _ in 0 .. 4 { 17 | _ := a.inc_to_limit(2) diff --git a/vlib/v/checker/tests/unexpected_or_propagate.out b/vlib/v/checker/tests/unexpected_or_propagate.out index 208bf88f81..411748d155 100644 --- a/vlib/v/checker/tests/unexpected_or_propagate.out +++ b/vlib/v/checker/tests/unexpected_or_propagate.out @@ -1,5 +1,5 @@ -vlib/v/checker/tests/unexpected_or_propagate.vv:6:17: error: unexpected `?`, the function `ret_zero`, does not return an optional - 4 | +vlib/v/checker/tests/unexpected_or_propagate.vv:6:17: error: unexpected `?`, the function `ret_zero` does not return an optional + 4 | 5 | fn opt_fn() ?int { 6 | a := ret_zero()? | ^ diff --git a/vlib/v/checker/tests/wrong_propagate_ret_type.out b/vlib/v/checker/tests/wrong_propagate_ret_type.out index 56f329f351..af8d737a4b 100644 --- a/vlib/v/checker/tests/wrong_propagate_ret_type.out +++ b/vlib/v/checker/tests/wrong_propagate_ret_type.out @@ -1,5 +1,5 @@ -vlib/v/checker/tests/wrong_propagate_ret_type.vv:6:17: error: to propagate the optional call, `opt_call` must itself return an optional - 4 | +vlib/v/checker/tests/wrong_propagate_ret_type.vv:6:17: error: to propagate the optional call, `opt_call` must return an optional + 4 | 5 | fn opt_call() int { 6 | a := ret_none()? | ^