Skip to content

Commit c583237

Browse files
authored
checker, cgen, parser: fix Option/Result error messages (capitalized) (#17486)
1 parent 0ba0fb2 commit c583237

27 files changed

+60
-60
lines changed

vlib/v/checker/checker.v

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ fn (mut c Checker) check_expr_opt_call(expr ast.Expr, ret_type ast.Type) ast.Typ
992992
return_modifier_kind := if expr_ret_type.has_flag(.option) {
993993
'an Option'
994994
} else {
995-
'a result'
995+
'a Result'
996996
}
997997
return_modifier := if expr_ret_type.has_flag(.option) { '?' } else { '!' }
998998
if expr_ret_type.has_flag(.result) && expr.or_block.kind == .absent {
@@ -1010,21 +1010,21 @@ fn (mut c Checker) check_expr_opt_call(expr ast.Expr, ret_type ast.Type) ast.Typ
10101010
}
10111011
return ret_type.clear_flag(.result)
10121012
} else if expr.or_block.kind == .block {
1013-
c.error('unexpected `or` block, the function `${expr.name}` does not return an Option or a result',
1013+
c.error('unexpected `or` block, the function `${expr.name}` does not return an Option or a Result',
10141014
expr.or_block.pos)
10151015
} else if expr.or_block.kind == .propagate_option {
10161016
c.error('unexpected `?`, the function `${expr.name}` does not return an Option',
10171017
expr.or_block.pos)
10181018
} else if expr.or_block.kind == .propagate_result {
1019-
c.error('unexpected `!`, the function `${expr.name}` does not return a result',
1019+
c.error('unexpected `!`, the function `${expr.name}` does not return a Result',
10201020
expr.or_block.pos)
10211021
}
10221022
} else if expr is ast.SelectorExpr && c.table.sym(ret_type).kind != .chan {
10231023
if expr.typ.has_flag(.option) || expr.typ.has_flag(.result) {
10241024
with_modifier_kind := if expr.typ.has_flag(.option) {
10251025
'an Option'
10261026
} else {
1027-
'a result'
1027+
'a Result'
10281028
}
10291029
with_modifier := if expr.typ.has_flag(.option) { '?' } else { '!' }
10301030
if expr.typ.has_flag(.result) && expr.or_block.kind == .absent {
@@ -1042,13 +1042,13 @@ fn (mut c Checker) check_expr_opt_call(expr ast.Expr, ret_type ast.Type) ast.Typ
10421042
}
10431043
return ret_type.clear_flag(.result)
10441044
} else if expr.or_block.kind == .block {
1045-
c.error('unexpected `or` block, the field `${expr.field_name}` is neither an Option, nor a result',
1045+
c.error('unexpected `or` block, the field `${expr.field_name}` is neither an Option, nor a Result',
10461046
expr.or_block.pos)
10471047
} else if expr.or_block.kind == .propagate_option {
10481048
c.error('unexpected `?`, the field `${expr.field_name}` is not an Option',
10491049
expr.or_block.pos)
10501050
} else if expr.or_block.kind == .propagate_result {
1051-
c.error('unexpected `!`, result fields are not supported', expr.or_block.pos)
1051+
c.error('unexpected `!`, Result fields are not supported', expr.or_block.pos)
10521052
}
10531053
} else if expr is ast.IndexExpr {
10541054
if expr.or_expr.kind != .absent {
@@ -1077,7 +1077,7 @@ fn (mut c Checker) check_or_expr(node ast.OrExpr, ret_type ast.Type, expr_return
10771077
}
10781078
if expr !is ast.Ident && !expr_return_type.has_flag(.option) {
10791079
if expr_return_type.has_flag(.result) {
1080-
c.warn('propagating a result like an Option is deprecated, use `foo()!` instead of `foo()?`',
1080+
c.warn('propagating a Result like an Option is deprecated, use `foo()!` instead of `foo()?`',
10811081
node.pos)
10821082
} else {
10831083
c.error('to propagate an Option, the call must also return an Option type',
@@ -1090,11 +1090,11 @@ fn (mut c Checker) check_or_expr(node ast.OrExpr, ret_type ast.Type, expr_return
10901090
if c.table.cur_fn != unsafe { nil } && !c.table.cur_fn.return_type.has_flag(.result)
10911091
&& !c.table.cur_fn.is_main && !c.table.cur_fn.is_test && !c.inside_const {
10921092
c.add_instruction_for_result_type()
1093-
c.error('to propagate the call, `${c.table.cur_fn.name}` must return a result type',
1093+
c.error('to propagate the call, `${c.table.cur_fn.name}` must return a Result type',
10941094
node.pos)
10951095
}
10961096
if !expr_return_type.has_flag(.result) {
1097-
c.error('to propagate a result, the call must also return a result type',
1097+
c.error('to propagate a Result, the call must also return a Result type',
10981098
node.pos)
10991099
}
11001100
return
@@ -1307,7 +1307,7 @@ fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type {
13071307
c.error('cannot access fields of an Option, handle the error with `or {...}` or propagate it with `?`',
13081308
node.pos)
13091309
} else if node.expr_type.has_flag(.result) {
1310-
c.error('cannot access fields of a result, handle the error with `or {...}` or propagate it with `!`',
1310+
c.error('cannot access fields of a Result, handle the error with `or {...}` or propagate it with `!`',
13111311
node.pos)
13121312
}
13131313
}
@@ -2428,13 +2428,13 @@ pub fn (mut c Checker) expr(node_ ast.Expr) ast.Type {
24282428
}
24292429
if !ret_type.has_flag(.option) && !ret_type.has_flag(.result) {
24302430
if node.or_block.kind == .block {
2431-
c.error('unexpected `or` block, the function `${node.name}` does not return an Option or a result',
2431+
c.error('unexpected `or` block, the function `${node.name}` does not return an Option or a Result',
24322432
node.or_block.pos)
24332433
} else if node.or_block.kind == .propagate_option {
2434-
c.error('unexpected `?`, the function `${node.name}` does not return an Option or a result',
2434+
c.error('unexpected `?`, the function `${node.name}` does not return an Option or a Result',
24352435
node.or_block.pos)
24362436
} else if node.or_block.kind == .propagate_result {
2437-
c.error('unexpected `!`, the function `${node.name}` does not return an Option or a result',
2437+
c.error('unexpected `!`, the function `${node.name}` does not return an Option or a Result',
24382438
node.or_block.pos)
24392439
}
24402440
}
@@ -2527,7 +2527,7 @@ pub fn (mut c Checker) expr(node_ ast.Expr) ast.Type {
25272527
else {}
25282528
}
25292529
if no_opt_or_res {
2530-
c.error('expression should either return an Option or a result', node.expr.pos())
2530+
c.error('expression should either return an Option or a Result', node.expr.pos())
25312531
}
25322532
}
25332533
return ast.bool_type
@@ -2605,13 +2605,13 @@ pub fn (mut c Checker) expr(node_ ast.Expr) ast.Type {
26052605

26062606
if !ret_type.has_flag(.option) && !ret_type.has_flag(.result) {
26072607
if node.or_block.kind == .block {
2608-
c.error('unexpected `or` block, the field `${node.field_name}` is neither an Option, nor a result',
2608+
c.error('unexpected `or` block, the field `${node.field_name}` is neither an Option, nor a Result',
26092609
node.or_block.pos)
26102610
} else if node.or_block.kind == .propagate_option {
2611-
c.error('unexpected `?`, the field `${node.field_name}` is neither an Option, nor a result',
2611+
c.error('unexpected `?`, the field `${node.field_name}` is neither an Option, nor a Result',
26122612
node.or_block.pos)
26132613
} else if node.or_block.kind == .propagate_result {
2614-
c.error('unexpected `!`, the field `${node.field_name}` is neither an Option, nor a result',
2614+
c.error('unexpected `!`, the field `${node.field_name}` is neither an Option, nor a Result',
26152615
node.or_block.pos)
26162616
}
26172617
}
@@ -2736,7 +2736,7 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
27362736
mut final_to_sym := c.table.final_sym(to_type)
27372737

27382738
if to_type.has_flag(.result) {
2739-
c.error('casting to result type is forbidden', node.pos)
2739+
c.error('casting to Result type is forbidden', node.pos)
27402740
}
27412741

27422742
if (to_sym.is_number() && from_sym.name == 'JS.Number')
@@ -2852,7 +2852,7 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
28522852
msg := if from_type.has_flag(.option) {
28532853
'an Option'
28542854
} else if from_type.has_flag(.result) {
2855-
'a result'
2855+
'a Result'
28562856
} else {
28572857
'a variadic'
28582858
}
@@ -3872,7 +3872,7 @@ fn (mut c Checker) check_index(typ_sym &ast.TypeSymbol, index ast.Expr, index_ty
38723872
} else {
38733873
'(array type `${typ_sym.name}`)'
38743874
}
3875-
c.error('cannot use option or result as index ${type_str}', pos)
3875+
c.error('cannot use Option or Result as index ${type_str}', pos)
38763876
}
38773877
}
38783878
}
@@ -3922,7 +3922,7 @@ fn (mut c Checker) index_expr(mut node ast.IndexExpr) ast.Type {
39223922
node.left.pos())
39233923
}
39243924
} else if typ.has_flag(.result) {
3925-
c.error('type `!${typ_sym.name}` is a result, it does not support indexing', node.left.pos())
3925+
c.error('type `!${typ_sym.name}` is a Result, it does not support indexing', node.left.pos())
39263926
}
39273927
if typ_sym.kind == .string && !typ.is_ptr() && node.is_setter {
39283928
c.error('cannot assign to s[i] since V strings are immutable\n' +

vlib/v/checker/fn.v

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
115115
for multi_type in return_sym.info.types {
116116
multi_sym := c.table.sym(multi_type)
117117
if multi_type == ast.error_type {
118-
c.error('type `IError` cannot be used in multi-return, return an option instead',
118+
c.error('type `IError` cannot be used in multi-return, return an Option instead',
119119
node.return_type_pos)
120120
} else if multi_type.has_flag(.result) {
121-
c.error('result cannot be used in multi-return, return a result instead',
121+
c.error('result cannot be used in multi-return, return a Result instead',
122122
node.return_type_pos)
123123
} else if multi_sym.kind == .array_fixed {
124124
c.error('fixed array cannot be used in multi-return', node.return_type_pos)
@@ -212,7 +212,7 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
212212
param.pos)
213213
}
214214
if param.typ.has_flag(.result) {
215-
c.error('result type argument is not supported currently', param.type_pos)
215+
c.error('Result type argument is not supported currently', param.type_pos)
216216
}
217217
arg_typ_sym := c.table.sym(param.typ)
218218
if arg_typ_sym.info is ast.Struct {
@@ -513,12 +513,12 @@ fn (mut c Checker) call_expr(mut node ast.CallExpr) ast.Type {
513513
if node.or_block.kind == .propagate_result && !c.table.cur_fn.return_type.has_flag(.result)
514514
&& !c.table.cur_fn.return_type.has_flag(.option) {
515515
c.add_instruction_for_result_type()
516-
c.error('to propagate the result call, `${c.table.cur_fn.name}` must return a result',
516+
c.error('to propagate the Result call, `${c.table.cur_fn.name}` must return a Result',
517517
node.or_block.pos)
518518
}
519519
if node.or_block.kind == .propagate_option && !c.table.cur_fn.return_type.has_flag(.option) {
520520
c.add_instruction_for_option_type()
521-
c.error('to propagate the option call, `${c.table.cur_fn.name}` must return an option',
521+
c.error('to propagate the Option call, `${c.table.cur_fn.name}` must return an Option',
522522
node.or_block.pos)
523523
}
524524
}
@@ -1346,10 +1346,10 @@ fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
13461346
'unknown method or field: `${left_sym.name}.${method_name}`'
13471347
}
13481348
if left_type.has_flag(.option) && method_name != 'str' {
1349-
c.error('option type cannot be called directly', node.left.pos())
1349+
c.error('Option type cannot be called directly', node.left.pos())
13501350
return ast.void_type
13511351
} else if left_type.has_flag(.result) {
1352-
c.error('result type cannot be called directly', node.left.pos())
1352+
c.error('Result type cannot be called directly', node.left.pos())
13531353
return ast.void_type
13541354
}
13551355
if left_sym.kind in [.sum_type, .interface_] {

vlib/v/checker/for.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ fn (mut c Checker) for_in_stmt(mut node ast.ForInStmt) {
115115
return
116116
}
117117
if !next_fn.return_type.has_flag(.option) {
118-
c.error('iterator method `next()` must return an option', node.cond.pos())
118+
c.error('iterator method `next()` must return an Option', node.cond.pos())
119119
}
120120
return_sym := c.table.sym(next_fn.return_type)
121121
if return_sym.kind == .multi_return {

vlib/v/checker/struct.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn (mut c Checker) struct_decl(mut node ast.StructDecl) {
7272

7373
for i, field in node.fields {
7474
if field.typ.has_flag(.result) {
75-
c.error('struct field does not support storing result', field.option_pos)
75+
c.error('struct field does not support storing Result', field.option_pos)
7676
}
7777
c.ensure_type_exists(field.typ, field.type_pos) or { return }
7878
c.ensure_generic_type_specify_type_names(field.typ, field.type_pos) or { return }

vlib/v/checker/tests/alias_type_cast_option_result_unhandled_err.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
vlib/v/checker/tests/alias_type_cast_option_result_unhandled_err.vv:15:12: error: ret_abc_result() returns a result, so it should have either an `or {}` block, or `!` at the end
1+
vlib/v/checker/tests/alias_type_cast_option_result_unhandled_err.vv:15:12: error: ret_abc_result() returns a Result, so it should have either an `or {}` block, or `!` at the end
22
13 | }
33
14 |
44
15 | a := Alias(ret_abc_result())

vlib/v/checker/tests/as_cast_option_result_unhandled_err.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
vlib/v/checker/tests/as_cast_option_result_unhandled_err.vv:11:6: error: ret_sum_result() returns a result, so it should have either an `or {}` block, or `!` at the end
1+
vlib/v/checker/tests/as_cast_option_result_unhandled_err.vv:11:6: error: ret_sum_result() returns a Result, so it should have either an `or {}` block, or `!` at the end
22
9 | }
33
10 |
44
11 | _ := ret_sum_result() as int

vlib/v/checker/tests/expression_should_return_an_option.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
vlib/v/checker/tests/expression_should_return_an_option.vv:26:10: error: expression should either return an Option or a result
1+
vlib/v/checker/tests/expression_should_return_an_option.vv:26:10: error: expression should either return an Option or a Result
22
24 | return_option(true) or { println(err) }
33
25 | // should be an checker error:
44
26 | if x := return_string() {

vlib/v/checker/tests/fn_return_or_err.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
vlib/v/checker/tests/fn_return_or_err.vv:6:17: error: unexpected `or` block, the function `pop` does not return an Option or a result
1+
vlib/v/checker/tests/fn_return_or_err.vv:6:17: error: unexpected `or` block, the function `pop` does not return an Option or a Result
22
4 |
33
5 | pub fn next(mut v []Typ) Typ {
44
6 | return v.pop() or { Typ{} }

vlib/v/checker/tests/go_wait_or.out

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
vlib/v/checker/tests/go_wait_or.vv:11:16: error: unexpected `?`, the function `wait` does not return an Option or a result
1+
vlib/v/checker/tests/go_wait_or.vv:11:16: error: unexpected `?`, the function `wait` does not return an Option or a Result
22
9 | spawn d(1)
33
10 | ]
44
11 | r := tg.wait()?
55
| ^
66
12 | println(r)
77
13 | s := tg[0].wait() or { panic('problem') }
8-
vlib/v/checker/tests/go_wait_or.vv:13:20: error: unexpected `or` block, the function `wait` does not return an Option or a result
8+
vlib/v/checker/tests/go_wait_or.vv:13:20: error: unexpected `or` block, the function `wait` does not return an Option or a Result
99
11 | r := tg.wait()?
1010
12 | println(r)
1111
13 | s := tg[0].wait() or { panic('problem') }
1212
| ~~~~~~~~~~~~~~~~~~~~~~~
1313
14 | println(s)
1414
15 | tg2 := [
15-
vlib/v/checker/tests/go_wait_or.vv:19:13: error: unexpected `or` block, the function `wait` does not return an Option or a result
15+
vlib/v/checker/tests/go_wait_or.vv:19:13: error: unexpected `or` block, the function `wait` does not return an Option or a Result
1616
17 | spawn e(1)
1717
18 | ]
1818
19 | tg2.wait() or { panic('problem') }
1919
| ~~~~~~~~~~~~~~~~~~~~~~~
2020
20 | tg2[0].wait()?
2121
21 | tg3 := [
22-
vlib/v/checker/tests/go_wait_or.vv:20:15: error: unexpected `?`, the function `wait` does not return an Option or a result
22+
vlib/v/checker/tests/go_wait_or.vv:20:15: error: unexpected `?`, the function `wait` does not return an Option or a Result
2323
18 | ]
2424
19 | tg2.wait() or { panic('problem') }
2525
20 | tg2[0].wait()?

vlib/v/checker/tests/ierror_in_return_tuple.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
vlib/v/checker/tests/ierror_in_return_tuple.vv:1:29: error: type `IError` cannot be used in multi-return, return an option instead
1+
vlib/v/checker/tests/ierror_in_return_tuple.vv:1:29: error: type `IError` cannot be used in multi-return, return an Option instead
22
1 | fn return_ierror_in_tuple() (bool, IError) {
33
| ~~~~~~~~~~~~~~
44
2 | return false, error('')

0 commit comments

Comments
 (0)