diff --git a/vlib/v/ast/cflags.v b/vlib/v/ast/cflags.v index 5f0be4cfec..559325bb26 100644 --- a/vlib/v/ast/cflags.v +++ b/vlib/v/ast/cflags.v @@ -17,12 +17,12 @@ fn (t &Table) has_cflag(flag cflag.CFlag) bool { // parse the flags to (ast.cflags) []CFlag // Note: clean up big time (joe-c) -pub fn (mut t Table) parse_cflag(cflg string, mod string, ctimedefines []string) ?bool { +pub fn (mut t Table) parse_cflag(cflg string, mod string, ctimedefines []string) ! { allowed_flags := ['framework', 'library', 'Wa', 'Wl', 'Wp', 'I', 'l', 'L', 'D'] flag_orig := cflg.trim_space() mut flag := flag_orig if flag == '' { - return none + return error('flag is empty') } mut fos := '' mut allowed_os_overrides := ['linux', 'darwin', 'freebsd', 'openbsd', 'windows', 'mingw', @@ -32,7 +32,7 @@ pub fn (mut t Table) parse_cflag(cflg string, mod string, ctimedefines []string) if !flag.starts_with(os_override) { continue } - pos := flag.index(' ') or { return none } + pos := flag.index(' ') or { return error('none') } fos = flag[..pos].trim_space() flag = flag[pos..].trim_space() } @@ -86,5 +86,4 @@ pub fn (mut t Table) parse_cflag(cflg string, mod string, ctimedefines []string) break } } - return true } diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index a62e7949a9..4f7bd3d9e5 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -337,7 +337,7 @@ pub fn (mut t TypeSymbol) register_method(new_fn Fn) int { return t.methods.len - 1 } -pub fn (t &Table) register_aggregate_method(mut sym TypeSymbol, name string) ?Fn { +pub fn (t &Table) register_aggregate_method(mut sym TypeSymbol, name string) !Fn { if sym.kind != .aggregate { t.panic('Unexpected type symbol: $sym.kind') } @@ -369,21 +369,25 @@ pub fn (t &Table) has_method(s &TypeSymbol, name string) bool { } // find_method searches from current type up through each parent looking for method -pub fn (t &Table) find_method(s &TypeSymbol, name string) ?Fn { +pub fn (t &Table) find_method(s &TypeSymbol, name string) !Fn { mut ts := unsafe { s } for { if method := ts.find_method(name) { return method } if ts.kind == .aggregate { - return t.register_aggregate_method(mut ts, name) + if method := t.register_aggregate_method(mut ts, name) { + return method + } else { + return err + } } if ts.parent_idx == 0 { break } ts = t.type_symbols[ts.parent_idx] } - return none + return error('unknown method `$name`') } [params] @@ -410,7 +414,7 @@ pub fn (t &Table) get_embeds(sym &TypeSymbol, options GetEmbedsOptions) [][]Type return embeds } -pub fn (t &Table) find_method_from_embeds(sym &TypeSymbol, method_name string) ?(Fn, []Type) { +pub fn (t &Table) find_method_from_embeds(sym &TypeSymbol, method_name string) !(Fn, []Type) { if sym.info is Struct { mut found_methods := []Fn{} mut embed_of_found_methods := []Type{} @@ -460,17 +464,16 @@ pub fn (t &Table) find_method_from_embeds(sym &TypeSymbol, method_name string) ? } } } - return none + return error('') } // find_method_with_embeds searches for a given method, also looking through embedded fields -pub fn (t &Table) find_method_with_embeds(sym &TypeSymbol, method_name string) ?Fn { +pub fn (t &Table) find_method_with_embeds(sym &TypeSymbol, method_name string) !Fn { if func := t.find_method(sym, method_name) { return func } else { // look for embedded field - first_err := err - func, _ := t.find_method_from_embeds(sym, method_name) or { return first_err } + func, _ := t.find_method_from_embeds(sym, method_name) or { return err } return func } } @@ -487,7 +490,7 @@ pub fn (t &Table) get_embed_methods(sym &TypeSymbol) []Fn { return methods } -fn (t &Table) register_aggregate_field(mut sym TypeSymbol, name string) ?StructField { +fn (t &Table) register_aggregate_field(mut sym TypeSymbol, name string) !StructField { if sym.kind != .aggregate { t.panic('Unexpected type symbol: $sym.kind') } @@ -537,7 +540,7 @@ pub fn (t &Table) struct_fields(sym &TypeSymbol) []StructField { } // search from current type up through each parent looking for field -pub fn (t &Table) find_field(s &TypeSymbol, name string) ?StructField { +pub fn (t &Table) find_field(s &TypeSymbol, name string) !StructField { mut ts := unsafe { s } for { match mut ts.info { @@ -574,11 +577,11 @@ pub fn (t &Table) find_field(s &TypeSymbol, name string) ?StructField { } ts = t.type_symbols[ts.parent_idx] } - return none + return error('') } // find_field_from_embeds tries to find a field in the nested embeds -pub fn (t &Table) find_field_from_embeds(sym &TypeSymbol, field_name string) ?(StructField, []Type) { +pub fn (t &Table) find_field_from_embeds(sym &TypeSymbol, field_name string) !(StructField, []Type) { if sym.info is Struct { mut found_fields := []StructField{} mut embeds_of_found_fields := []Type{} @@ -611,11 +614,11 @@ pub fn (t &Table) find_field_from_embeds(sym &TypeSymbol, field_name string) ?(S unalias_sym := t.sym(sym.info.parent_type) return t.find_field_from_embeds(unalias_sym, field_name) } - return none + return error('') } // find_field_with_embeds searches for a given field, also looking through embedded fields -pub fn (t &Table) find_field_with_embeds(sym &TypeSymbol, field_name string) ?StructField { +pub fn (t &Table) find_field_with_embeds(sym &TypeSymbol, field_name string) !StructField { if field := t.find_field(sym, field_name) { return field } else { diff --git a/vlib/v/ast/walker/walker.v b/vlib/v/ast/walker/walker.v index 6cd2c103ee..92341e3218 100644 --- a/vlib/v/ast/walker/walker.v +++ b/vlib/v/ast/walker/walker.v @@ -5,7 +5,7 @@ import v.ast // Visitor defines a visit method which is invoked by the walker in each node it encounters. pub interface Visitor { mut: - visit(node &ast.Node) ? + visit(node &ast.Node) ! } pub type InspectorFn = fn (node &ast.Node, data voidptr) bool @@ -16,7 +16,7 @@ mut: data voidptr } -pub fn (i &Inspector) visit(node &ast.Node) ? { +pub fn (i &Inspector) visit(node &ast.Node) ! { if i.inspector_callback(node, i.data) { return } diff --git a/vlib/v/ast/walker/walker_test.v b/vlib/v/ast/walker/walker_test.v index 66eaa31f90..4a370cacc5 100644 --- a/vlib/v/ast/walker/walker_test.v +++ b/vlib/v/ast/walker/walker_test.v @@ -15,7 +15,7 @@ mut: node ast.Node } -fn (mut n NodeByOffset) visit(node &ast.Node) ? { +fn (mut n NodeByOffset) visit(node &ast.Node) ! { node_pos := node.pos() if n.pos >= node_pos.pos && n.pos <= node_pos.pos + node_pos.len && node !is ast.File { n.node = node diff --git a/vlib/v/builder/builder.v b/vlib/v/builder/builder.v index fa822b1f7a..7049e0b309 100644 --- a/vlib/v/builder/builder.v +++ b/vlib/v/builder/builder.v @@ -88,7 +88,7 @@ pub fn new_builder(pref &pref.Preferences) Builder { } } -pub fn (mut b Builder) front_stages(v_files []string) ? { +pub fn (mut b Builder) front_stages(v_files []string) ! { mut timers := util.get_timers() util.timing_start('PARSE') @@ -106,7 +106,7 @@ pub fn (mut b Builder) front_stages(v_files []string) ? { } } -pub fn (mut b Builder) middle_stages() ? { +pub fn (mut b Builder) middle_stages() ! { util.timing_start('CHECK') util.timing_start('Checker.generic_insts_to_concrete') @@ -135,9 +135,9 @@ pub fn (mut b Builder) middle_stages() ? { } } -pub fn (mut b Builder) front_and_middle_stages(v_files []string) ? { - b.front_stages(v_files)? - b.middle_stages()? +pub fn (mut b Builder) front_and_middle_stages(v_files []string) ! { + b.front_stages(v_files)! + b.middle_stages()! } // parse all deps from already parsed files diff --git a/vlib/v/builder/cc_windows.v b/vlib/v/builder/cc_windows.v index b9b472fa04..2fe71b77e4 100644 --- a/vlib/v/builder/cc_windows.v +++ b/vlib/v/builder/cc_windows.v @@ -6,7 +6,7 @@ module builder import os import v.pref -pub fn (mut v Builder) find_win_cc() ? { +pub fn (mut v Builder) find_win_cc() ! { $if !windows { return } diff --git a/vlib/v/builder/interpreterbuilder/v_interpret_test.v b/vlib/v/builder/interpreterbuilder/v_interpret_test.v index 1960a90b9b..ca6b8c2b31 100644 --- a/vlib/v/builder/interpreterbuilder/v_interpret_test.v +++ b/vlib/v/builder/interpreterbuilder/v_interpret_test.v @@ -8,7 +8,7 @@ fn interpreter_wrap(a string) string { return 'fn main() {$a}' } -fn interp_test(expression string, expected string) ? { +fn interp_test(expression string, expected string) ! { tmpdir := os.join_path(os.temp_dir(), 'v', 'interpret_test_$rand.ulid()') os.mkdir_all(tmpdir) or {} defer { @@ -17,12 +17,12 @@ fn interp_test(expression string, expected string) ? { // tmpfile := os.join_path(tmpdir, 'input.v') outfile := os.join_path(tmpdir, 'output.txt') - os.write_file(tmpfile, interpreter_wrap(expression))? + os.write_file(tmpfile, interpreter_wrap(expression))! if os.system('${os.quoted_path(vexe)} interpret ${os.quoted_path(tmpfile)} > ${os.quoted_path(outfile)}') != 0 { eprintln('>>> Failed to interpret V expression: |$expression|') return error('v interp') } - res := os.read_file(outfile)? + res := os.read_file(outfile)! output := res.trim_space() if output != expected { eprintln('>>> The output of the V expression, is not the same as the expected one') @@ -49,7 +49,7 @@ fn test_interpreter() { tests << InterpTest{'println(3*3)', '9'} tests << InterpTest{'a := 3\nprintln(a*3)', '9'} for test in tests { - interp_test(test.input, test.output)? + interp_test(test.input, test.output)! assert true } } diff --git a/vlib/v/callgraph/callgraph.v b/vlib/v/callgraph/callgraph.v index d8c9e4d74e..48918bd121 100644 --- a/vlib/v/callgraph/callgraph.v +++ b/vlib/v/callgraph/callgraph.v @@ -83,7 +83,7 @@ fn (mut m Mapper) dot_fn_name(fname string, recv_type ast.Type, is_method bool) return 'Node_fn_' + m.dot_normalise_node_name(fname) } -fn (mut m Mapper) visit(node &ast.Node) ? { +fn (mut m Mapper) visit(node &ast.Node) ! { m.node = unsafe { node } match node { ast.File { diff --git a/vlib/v/checker/check_types.v b/vlib/v/checker/check_types.v index ab2aa0356b..a869fc700a 100644 --- a/vlib/v/checker/check_types.v +++ b/vlib/v/checker/check_types.v @@ -599,7 +599,7 @@ fn (c &Checker) promote_num(left_type ast.Type, right_type ast.Type) ast.Type { } } -pub fn (mut c Checker) check_expected(got ast.Type, expected ast.Type) ? { +pub fn (mut c Checker) check_expected(got ast.Type, expected ast.Type) ! { if !c.check_types(got, expected) { return error(c.expected_msg(got, expected)) } diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index e1da077e08..4747a63f62 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -3199,16 +3199,16 @@ pub fn (mut c Checker) unsafe_expr(mut node ast.UnsafeExpr) ast.Type { return t } -fn (mut c Checker) find_definition(ident ast.Ident) ?ast.Expr { +fn (mut c Checker) find_definition(ident ast.Ident) !ast.Expr { match ident.kind { - .unresolved, .blank_ident { return none } + .unresolved, .blank_ident { return error('none') } .variable, .constant { return c.find_obj_definition(ident.obj) } .global { return error('$ident.name is a global variable') } .function { return error('$ident.name is a function') } } } -fn (mut c Checker) find_obj_definition(obj ast.ScopeObject) ?ast.Expr { +fn (mut c Checker) find_obj_definition(obj ast.ScopeObject) !ast.Expr { // TODO: remove once we have better type inference mut name := '' match obj { diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 7a1288f4dd..085840a73e 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -1914,7 +1914,7 @@ fn (mut c Checker) post_process_generic_fns() { } } -pub fn (mut c Checker) check_expected_arg_count(mut node ast.CallExpr, f &ast.Fn) ? { +pub fn (mut c Checker) check_expected_arg_count(mut node ast.CallExpr, f &ast.Fn) ! { nr_args := node.args.len nr_params := if node.is_method && f.params.len > 0 { f.params.len - 1 } else { f.params.len } mut min_required_params := f.params.len diff --git a/vlib/v/fmt/fmt_keep_test.v b/vlib/v/fmt/fmt_keep_test.v index 375bc90cea..56f0fd4c53 100644 --- a/vlib/v/fmt/fmt_keep_test.v +++ b/vlib/v/fmt/fmt_keep_test.v @@ -97,10 +97,10 @@ fn prepare_bin2v_file(mut fmt_bench benchmark.Benchmark) { eprintln(fmt_bench.step_message_ok('Prepared bin2v_keep.vv')) } -fn write_bin2v_keep_content() ? { +fn write_bin2v_keep_content() ! { img0 := os.join_path('vlib', 'v', 'embed_file', 'tests', 'v.png') img1 := os.join_path('tutorials', 'building_a_simple_web_blog_with_vweb', 'img', 'time.png') - os.rm(b2v_keep_path)? + os.rm(b2v_keep_path)! res := os.execute('${os.quoted_path(vexe)} bin2v -w ${os.quoted_path(b2v_keep_path)} ${os.quoted_path(img0)} ${os.quoted_path(img1)}') if res.exit_code != 0 { restore_bin2v_placeholder() or {} @@ -108,8 +108,8 @@ fn write_bin2v_keep_content() ? { } } -fn restore_bin2v_placeholder() ? { +fn restore_bin2v_placeholder() ! { text := '// This is a placeholder file which will be filled with bin2v output before the test. // HINT: do NOT delete, move or rename this file!\n' - os.write_file(b2v_keep_path, text)? + os.write_file(b2v_keep_path, text)! } diff --git a/vlib/v/gen/c/assert.v b/vlib/v/gen/c/assert.v index 1f3ef6ffbf..3456e1c0de 100644 --- a/vlib/v/gen/c/assert.v +++ b/vlib/v/gen/c/assert.v @@ -52,7 +52,7 @@ struct UnsupportedAssertCtempTransform { const unsupported_ctemp_assert_transform = IError(UnsupportedAssertCtempTransform{}) -fn (mut g Gen) assert_subexpression_to_ctemp(expr ast.Expr, expr_type ast.Type) ?ast.Expr { +fn (mut g Gen) assert_subexpression_to_ctemp(expr ast.Expr, expr_type ast.Type) !ast.Expr { match expr { ast.CallExpr { return g.new_ctemp_var_then_gen(expr, expr_type) diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index e679e7d69b..95315f62a6 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -417,7 +417,7 @@ fn (mut g Gen) gen_fn_decl(node &ast.FnDecl, skip bool) { } } -fn (mut g Gen) c_fn_name(node &ast.FnDecl) ?string { +fn (mut g Gen) c_fn_name(node &ast.FnDecl) !string { mut name := node.name if name in ['+', '-', '*', '/', '%', '<', '=='] { name = util.replace_op(name) @@ -425,7 +425,7 @@ fn (mut g Gen) c_fn_name(node &ast.FnDecl) ?string { if node.is_method { unwrapped_rec_sym := g.table.sym(g.unwrap_generic(node.receiver.typ)) if unwrapped_rec_sym.kind == .placeholder { - return none + return error('none') } name = g.cc_type(node.receiver.typ, false) + '_' + name } diff --git a/vlib/v/gen/js/comptime.v b/vlib/v/gen/js/comptime.v index 2bbcf0a568..97ac659169 100644 --- a/vlib/v/gen/js/comptime.v +++ b/vlib/v/gen/js/comptime.v @@ -168,7 +168,7 @@ fn (mut g JsGen) comptime_if_cond(cond ast.Expr, pkg_exist bool) bool { } } -fn (mut g JsGen) comptime_if_to_ifdef(name string, is_comptime_optional bool) ?string { +fn (mut g JsGen) comptime_if_to_ifdef(name string, is_comptime_optional bool) !string { match name { // platforms/os-es: 'windows' { @@ -313,5 +313,5 @@ fn (mut g JsGen) comptime_if_to_ifdef(name string, is_comptime_optional bool) ?s return error('bad os ifdef name "$name"') // should never happen, caught in the checker } } - return none + return error('none') } diff --git a/vlib/v/gen/js/js.v b/vlib/v/gen/js/js.v index ab0f63f590..7d9bab0464 100644 --- a/vlib/v/gen/js/js.v +++ b/vlib/v/gen/js/js.v @@ -1075,7 +1075,7 @@ struct UnsupportedAssertCtempTransform { const unsupported_ctemp_assert_transform = IError(UnsupportedAssertCtempTransform{}) -fn (mut g JsGen) assert_subexpression_to_ctemp(expr ast.Expr, expr_type ast.Type) ?ast.Expr { +fn (mut g JsGen) assert_subexpression_to_ctemp(expr ast.Expr, expr_type ast.Type) !ast.Expr { match expr { ast.CallExpr { return g.new_ctemp_var_then_gen(expr, expr_type) diff --git a/vlib/v/gen/js/program_test.v b/vlib/v/gen/js/program_test.v index 8754854359..be7bad3f90 100644 --- a/vlib/v/gen/js/program_test.v +++ b/vlib/v/gen/js/program_test.v @@ -35,7 +35,7 @@ fn test_node_exists() { println('Using node version: $version') } -fn test_running_programs_compiled_with_the_js_backend() ? { +fn test_running_programs_compiled_with_the_js_backend() { os.setenv('VCOLORS', 'never', true) os.chdir(vroot) or {} test_dir := 'vlib/v/gen/js/tests/testdata' @@ -50,21 +50,21 @@ fn get_main_files_in_dir(dir string) []string { return mfiles } -fn check_path(dir string, tests []string) ?int { +fn check_path(dir string, tests []string) !int { mut nb_fail := 0 paths := vtest.filter_vtest_only(tests, basepath: vroot) for path in paths { program := path.replace(vroot + os.path_separator, '') program_out := program.replace('.v', '.out') if !os.exists(program_out) { - os.write_file(program_out, '')? + os.write_file(program_out, '')! } print(program + ' ') res := os.execute('${os.quoted_path(vexe)} -b js_node run ${os.quoted_path(program)}') if res.exit_code < 0 { panic(res.output) } - mut expected := os.read_file(program_out)? + mut expected := os.read_file(program_out)! expected = clean_line_endings(expected) found := clean_line_endings(res.output) if expected != found { diff --git a/vlib/v/gen/native/gen.v b/vlib/v/gen/native/gen.v index bf8221bedf..4924ffdcc4 100644 --- a/vlib/v/gen/native/gen.v +++ b/vlib/v/gen/native/gen.v @@ -184,7 +184,7 @@ fn (mut g Gen) get_type_from_var(var Var) ast.Type { } } -fn get_backend(arch pref.Arch) ?CodeGen { +fn get_backend(arch pref.Arch) !CodeGen { match arch { .arm64 { return Arm64{ diff --git a/vlib/v/live/executable/reloader.v b/vlib/v/live/executable/reloader.v index f8643693a4..3051ddd8ef 100644 --- a/vlib/v/live/executable/reloader.v +++ b/vlib/v/live/executable/reloader.v @@ -54,7 +54,7 @@ fn elog(r &live.LiveReloadInfo, s string) { } } -fn compile_and_reload_shared_lib(mut r live.LiveReloadInfo) ?bool { +fn compile_and_reload_shared_lib(mut r live.LiveReloadInfo) !bool { sw := time.new_stopwatch() new_lib_path := compile_lib(mut r) or { return error('errors while compiling $r.original') } elog(r, '> compile_and_reload_shared_lib compiled: $new_lib_path') diff --git a/vlib/v/parser/expr.v b/vlib/v/parser/expr.v index eeeb387f67..44fd06d225 100644 --- a/vlib/v/parser/expr.v +++ b/vlib/v/parser/expr.v @@ -16,7 +16,7 @@ pub fn (mut p Parser) expr(precedence int) ast.Expr { } } -pub fn (mut p Parser) check_expr(precedence int) ?ast.Expr { +pub fn (mut p Parser) check_expr(precedence int) !ast.Expr { p.trace_parser('expr($precedence)') mut node := ast.empty_expr is_stmt_ident := p.is_stmt_ident @@ -363,7 +363,7 @@ pub fn (mut p Parser) check_expr(precedence int) ?ast.Expr { } if p.tok.kind != .eof && !(p.tok.kind == .rsbr && p.inside_asm) { // eof should be handled where it happens - return none + return error('none') // return p.unexpected(prepend_msg: 'invalid expression: ') } } diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 739a1d43be..1302977232 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -584,7 +584,7 @@ run them via `v file.v` instead', return fn_decl } -fn (mut p Parser) fn_receiver(mut params []ast.Param, mut rec ReceiverParsingInfo) ? { +fn (mut p Parser) fn_receiver(mut params []ast.Param, mut rec ReceiverParsingInfo) ! { p.inside_receiver_param = true defer { p.inside_receiver_param = false diff --git a/vlib/v/pref/options_test.v b/vlib/v/pref/options_test.v index d709d8aab8..04ecc3d03e 100644 --- a/vlib/v/pref/options_test.v +++ b/vlib/v/pref/options_test.v @@ -15,7 +15,7 @@ fn testsuite_end() { os.rmdir_all(tfolder) or {} } -fn test_cflags() ? { +fn test_cflags() { os.chdir(os.real_path(@VMODROOT)) or {} mut debug_arg := '-g3 -O0' mut optimised_arg := '-O1' diff --git a/vlib/v/pref/os.v b/vlib/v/pref/os.v index 410de3205c..6779463749 100644 --- a/vlib/v/pref/os.v +++ b/vlib/v/pref/os.v @@ -32,7 +32,7 @@ pub enum OS { } // Helper function to convert string names to OS enum -pub fn os_from_string(os_str string) ?OS { +pub fn os_from_string(os_str string) !OS { match os_str { '' { return ._auto diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index 93886e28f4..fb4ca7c796 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -888,7 +888,7 @@ pub fn (pref &Preferences) should_output_to_stdout() bool { return pref.out_name.ends_with('/-') || pref.out_name.ends_with(r'\-') } -pub fn arch_from_string(arch_str string) ?Arch { +pub fn arch_from_string(arch_str string) !Arch { match arch_str { 'amd64', 'x86_64', 'x64', 'x86' { // amd64 recommended @@ -947,7 +947,7 @@ fn is_source_file(path string) bool { return path.ends_with('.v') || os.exists(path) } -pub fn backend_from_string(s string) ?Backend { +pub fn backend_from_string(s string) !Backend { match s { 'c' { return .c } 'js' { return .js_node } diff --git a/vlib/v/preludes/test_runner.v b/vlib/v/preludes/test_runner.v index 4c77717761..18ac7c2728 100644 --- a/vlib/v/preludes/test_runner.v +++ b/vlib/v/preludes/test_runner.v @@ -121,5 +121,5 @@ pub fn change_test_runner(x &TestRunner) { // `vlib/sync/channel_close_test.v` compiles with simpler runners, // that do not `import os` (which has other `fn()?`). Without it, // the C `Option_void` type is undefined -> C compilation error. -fn vtest_option_cludge() ? { +fn vtest_option_cludge() ! { } diff --git a/vlib/v/token/token.v b/vlib/v/token/token.v index e82eca74ca..8f0a221b11 100644 --- a/vlib/v/token/token.v +++ b/vlib/v/token/token.v @@ -628,7 +628,7 @@ pub fn kind_to_string(k Kind) string { } } -pub fn kind_from_string(s string) ?Kind { +pub fn kind_from_string(s string) !Kind { return match s { 'unknown' { .unknown } 'eof' { .eof } diff --git a/vlib/v/util/diff.v b/vlib/v/util/diff.v index 3e1814e9f0..ceba7073b5 100644 --- a/vlib/v/util/diff.v +++ b/vlib/v/util/diff.v @@ -4,7 +4,7 @@ import v.util.diff // iterates through a list of known diff cli commands // and returns it with basic options -pub fn find_working_diff_command() ?string { +pub fn find_working_diff_command() !string { return diff.find_working_diff_command() } diff --git a/vlib/v/util/diff/diff.v b/vlib/v/util/diff/diff.v index 8d12c0c45f..195cec774f 100644 --- a/vlib/v/util/diff/diff.v +++ b/vlib/v/util/diff/diff.v @@ -5,7 +5,7 @@ import time // iterates through a list of known diff cli commands // and returns it with basic options -pub fn find_working_diff_command() ?string { +pub fn find_working_diff_command() !string { env_difftool := os.getenv('VDIFF_TOOL') env_diffopts := os.getenv('VDIFF_OPTIONS') if env_difftool != '' { diff --git a/vlib/v/util/module.v b/vlib/v/util/module.v index 0454878a4b..555a6eab8a 100644 --- a/vlib/v/util/module.v +++ b/vlib/v/util/module.v @@ -96,7 +96,7 @@ pub fn qualify_module(pref &pref.Preferences, mod string, file_path string) stri // 2022-01-30 just on windows, because while `vlib\v\checker\tests\modules\deprecated_module` works, // 2022-01-30 it leads to path differences, and the / version on windows triggers a module lookip bug, // 2022-01-30 leading to completely different errors) -fn mod_path_to_full_name(pref &pref.Preferences, mod string, path string) ?string { +fn mod_path_to_full_name(pref &pref.Preferences, mod string, path string) !string { // TODO: explore using `pref.lookup_path` & `os.vmodules_paths()` // absolute paths instead of 'vlib' & '.vmodules' mut vmod_folders := ['vlib', '.vmodules', 'modules'] diff --git a/vlib/v/util/util.v b/vlib/v/util/util.v index 7c148d276c..5e69155e43 100644 --- a/vlib/v/util/util.v +++ b/vlib/v/util/util.v @@ -62,7 +62,7 @@ pub fn set_vroot_folder(vroot_path string) { os.setenv('VCHILD', 'true', true) } -pub fn resolve_vmodroot(str string, dir string) ?string { +pub fn resolve_vmodroot(str string, dir string) !string { mut mcache := vmod.get_cache() vmod_file_location := mcache.get_by_folder(dir) if vmod_file_location.vmod_file.len == 0 { @@ -75,7 +75,7 @@ pub fn resolve_vmodroot(str string, dir string) ?string { // resolve_env_value replaces all occurrences of `$env('ENV_VAR_NAME')` // in `str` with the value of the env variable `$ENV_VAR_NAME`. -pub fn resolve_env_value(str string, check_for_presence bool) ?string { +pub fn resolve_env_value(str string, check_for_presence bool) !string { env_ident := "\$env('" at := str.index(env_ident) or { return error('no "$env_ident' + '...\')" could be found in "$str".') @@ -296,7 +296,7 @@ mut: } [unsafe] -pub fn cached_read_source_file(path string) ?string { +pub fn cached_read_source_file(path string) !string { mut static cache := &SourceCache(0) if cache == unsafe { nil } { cache = &SourceCache{} @@ -366,7 +366,7 @@ fn non_empty(arg []string) []string { return arg.filter(it != '') } -pub fn check_module_is_installed(modulename string, is_verbose bool) ?bool { +pub fn check_module_is_installed(modulename string, is_verbose bool) !bool { mpath := os.join_path_single(os.vmodules_dir(), modulename) mod_v_file := os.join_path_single(mpath, 'v.mod') murl := 'https://github.com/vlang/$modulename' @@ -510,7 +510,7 @@ pub fn should_bundle_module(mod string) bool { // find_all_v_files - given a list of files/folders, finds all .v/.vsh files // if some of the files/folders on the list does not exist, or a file is not // a .v or .vsh file, returns an error instead. -pub fn find_all_v_files(roots []string) ?[]string { +pub fn find_all_v_files(roots []string) ![]string { mut files := []string{} for file in roots { if os.is_dir(file) { @@ -539,6 +539,6 @@ pub fn free_caches() { } } -pub fn read_file(file_path string) ?string { +pub fn read_file(file_path string) !string { return unsafe { cached_read_source_file(file_path) } } diff --git a/vlib/v/vmod/parser.v b/vlib/v/vmod/parser.v index e59d09b90e..6e7883b3f7 100644 --- a/vlib/v/vmod/parser.v +++ b/vlib/v/vmod/parser.v @@ -52,7 +52,7 @@ struct Token { line int } -pub fn from_file(vmod_path string) ?Manifest { +pub fn from_file(vmod_path string) !Manifest { if !os.exists(vmod_path) { return error('v.mod: v.mod file not found.') } @@ -60,7 +60,7 @@ pub fn from_file(vmod_path string) ?Manifest { return decode(contents) } -pub fn decode(contents string) ?Manifest { +pub fn decode(contents string) !Manifest { mut parser := Parser{ scanner: Scanner{ pos: 0 @@ -158,7 +158,7 @@ fn (mut s Scanner) scan_all() { s.tokenize(.eof, 'eof') } -fn get_array_content(tokens []Token, st_idx int) ?([]string, int) { +fn get_array_content(tokens []Token, st_idx int) !([]string, int) { mut vals := []string{} mut idx := st_idx if tokens[idx].typ != .labr { @@ -187,7 +187,7 @@ fn get_array_content(tokens []Token, st_idx int) ?([]string, int) { return vals, idx } -fn (mut p Parser) parse() ?Manifest { +fn (mut p Parser) parse() !Manifest { if p.scanner.text.len == 0 { return error('$vmod.err_label no content.') } @@ -237,14 +237,14 @@ fn (mut p Parser) parse() ?Manifest { mn.author = field_value } 'dependencies' { - deps, idx := get_array_content(tokens, i + 1)? + deps, idx := get_array_content(tokens, i + 1)! mn.dependencies = deps i = idx continue } else { if tokens[i + 1].typ == .labr { - vals, idx := get_array_content(tokens, i + 1)? + vals, idx := get_array_content(tokens, i + 1)! mn.unknown[field_name] = vals i = idx continue