all: change optional to result in vlib/v. (#16177)

This commit is contained in:
yuyi 2022-10-24 16:51:20 +08:00 committed by GitHub
parent 26986104f9
commit 48f43f11ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 80 additions and 78 deletions

View File

@ -17,12 +17,12 @@ fn (t &Table) has_cflag(flag cflag.CFlag) bool {
// parse the flags to (ast.cflags) []CFlag // parse the flags to (ast.cflags) []CFlag
// Note: clean up big time (joe-c) // 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'] allowed_flags := ['framework', 'library', 'Wa', 'Wl', 'Wp', 'I', 'l', 'L', 'D']
flag_orig := cflg.trim_space() flag_orig := cflg.trim_space()
mut flag := flag_orig mut flag := flag_orig
if flag == '' { if flag == '' {
return none return error('flag is empty')
} }
mut fos := '' mut fos := ''
mut allowed_os_overrides := ['linux', 'darwin', 'freebsd', 'openbsd', 'windows', 'mingw', 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) { if !flag.starts_with(os_override) {
continue continue
} }
pos := flag.index(' ') or { return none } pos := flag.index(' ') or { return error('none') }
fos = flag[..pos].trim_space() fos = flag[..pos].trim_space()
flag = 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 break
} }
} }
return true
} }

View File

@ -337,7 +337,7 @@ pub fn (mut t TypeSymbol) register_method(new_fn Fn) int {
return t.methods.len - 1 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 { if sym.kind != .aggregate {
t.panic('Unexpected type symbol: $sym.kind') 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 // 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 } mut ts := unsafe { s }
for { for {
if method := ts.find_method(name) { if method := ts.find_method(name) {
return method return method
} }
if ts.kind == .aggregate { 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 { if ts.parent_idx == 0 {
break break
} }
ts = t.type_symbols[ts.parent_idx] ts = t.type_symbols[ts.parent_idx]
} }
return none return error('unknown method `$name`')
} }
[params] [params]
@ -410,7 +414,7 @@ pub fn (t &Table) get_embeds(sym &TypeSymbol, options GetEmbedsOptions) [][]Type
return embeds 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 { if sym.info is Struct {
mut found_methods := []Fn{} mut found_methods := []Fn{}
mut embed_of_found_methods := []Type{} 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 // 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) { if func := t.find_method(sym, method_name) {
return func return func
} else { } else {
// look for embedded field // look for embedded field
first_err := err func, _ := t.find_method_from_embeds(sym, method_name) or { return err }
func, _ := t.find_method_from_embeds(sym, method_name) or { return first_err }
return func return func
} }
} }
@ -487,7 +490,7 @@ pub fn (t &Table) get_embed_methods(sym &TypeSymbol) []Fn {
return methods 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 { if sym.kind != .aggregate {
t.panic('Unexpected type symbol: $sym.kind') 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 // 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 } mut ts := unsafe { s }
for { for {
match mut ts.info { 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] ts = t.type_symbols[ts.parent_idx]
} }
return none return error('')
} }
// find_field_from_embeds tries to find a field in the nested embeds // 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 { if sym.info is Struct {
mut found_fields := []StructField{} mut found_fields := []StructField{}
mut embeds_of_found_fields := []Type{} 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) unalias_sym := t.sym(sym.info.parent_type)
return t.find_field_from_embeds(unalias_sym, field_name) 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 // 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) { if field := t.find_field(sym, field_name) {
return field return field
} else { } else {

View File

@ -5,7 +5,7 @@ import v.ast
// Visitor defines a visit method which is invoked by the walker in each node it encounters. // Visitor defines a visit method which is invoked by the walker in each node it encounters.
pub interface Visitor { pub interface Visitor {
mut: mut:
visit(node &ast.Node) ? visit(node &ast.Node) !
} }
pub type InspectorFn = fn (node &ast.Node, data voidptr) bool pub type InspectorFn = fn (node &ast.Node, data voidptr) bool
@ -16,7 +16,7 @@ mut:
data voidptr 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) { if i.inspector_callback(node, i.data) {
return return
} }

View File

@ -15,7 +15,7 @@ mut:
node ast.Node node ast.Node
} }
fn (mut n NodeByOffset) visit(node &ast.Node) ? { fn (mut n NodeByOffset) visit(node &ast.Node) ! {
node_pos := node.pos() node_pos := node.pos()
if n.pos >= node_pos.pos && n.pos <= node_pos.pos + node_pos.len && node !is ast.File { if n.pos >= node_pos.pos && n.pos <= node_pos.pos + node_pos.len && node !is ast.File {
n.node = node n.node = node

View File

@ -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() mut timers := util.get_timers()
util.timing_start('PARSE') 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('CHECK')
util.timing_start('Checker.generic_insts_to_concrete') 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) ? { pub fn (mut b Builder) front_and_middle_stages(v_files []string) ! {
b.front_stages(v_files)? b.front_stages(v_files)!
b.middle_stages()? b.middle_stages()!
} }
// parse all deps from already parsed files // parse all deps from already parsed files

View File

@ -6,7 +6,7 @@ module builder
import os import os
import v.pref import v.pref
pub fn (mut v Builder) find_win_cc() ? { pub fn (mut v Builder) find_win_cc() ! {
$if !windows { $if !windows {
return return
} }

View File

@ -8,7 +8,7 @@ fn interpreter_wrap(a string) string {
return 'fn main() {$a}' 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()') tmpdir := os.join_path(os.temp_dir(), 'v', 'interpret_test_$rand.ulid()')
os.mkdir_all(tmpdir) or {} os.mkdir_all(tmpdir) or {}
defer { defer {
@ -17,12 +17,12 @@ fn interp_test(expression string, expected string) ? {
// //
tmpfile := os.join_path(tmpdir, 'input.v') tmpfile := os.join_path(tmpdir, 'input.v')
outfile := os.join_path(tmpdir, 'output.txt') 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 { if os.system('${os.quoted_path(vexe)} interpret ${os.quoted_path(tmpfile)} > ${os.quoted_path(outfile)}') != 0 {
eprintln('>>> Failed to interpret V expression: |$expression|') eprintln('>>> Failed to interpret V expression: |$expression|')
return error('v interp') return error('v interp')
} }
res := os.read_file(outfile)? res := os.read_file(outfile)!
output := res.trim_space() output := res.trim_space()
if output != expected { if output != expected {
eprintln('>>> The output of the V expression, is not the same as the expected one') 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{'println(3*3)', '9'}
tests << InterpTest{'a := 3\nprintln(a*3)', '9'} tests << InterpTest{'a := 3\nprintln(a*3)', '9'}
for test in tests { for test in tests {
interp_test(test.input, test.output)? interp_test(test.input, test.output)!
assert true assert true
} }
} }

View File

@ -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) 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 } m.node = unsafe { node }
match node { match node {
ast.File { ast.File {

View File

@ -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) { if !c.check_types(got, expected) {
return error(c.expected_msg(got, expected)) return error(c.expected_msg(got, expected))
} }

View File

@ -3199,16 +3199,16 @@ pub fn (mut c Checker) unsafe_expr(mut node ast.UnsafeExpr) ast.Type {
return t 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 { match ident.kind {
.unresolved, .blank_ident { return none } .unresolved, .blank_ident { return error('none') }
.variable, .constant { return c.find_obj_definition(ident.obj) } .variable, .constant { return c.find_obj_definition(ident.obj) }
.global { return error('$ident.name is a global variable') } .global { return error('$ident.name is a global variable') }
.function { return error('$ident.name is a function') } .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 // TODO: remove once we have better type inference
mut name := '' mut name := ''
match obj { match obj {

View File

@ -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_args := node.args.len
nr_params := if node.is_method && f.params.len > 0 { f.params.len - 1 } else { f.params.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 mut min_required_params := f.params.len

View File

@ -97,10 +97,10 @@ fn prepare_bin2v_file(mut fmt_bench benchmark.Benchmark) {
eprintln(fmt_bench.step_message_ok('Prepared bin2v_keep.vv')) 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') 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') 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)}') 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 { if res.exit_code != 0 {
restore_bin2v_placeholder() or {} 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. 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' // HINT: do NOT delete, move or rename this file!\n'
os.write_file(b2v_keep_path, text)? os.write_file(b2v_keep_path, text)!
} }

View File

@ -52,7 +52,7 @@ struct UnsupportedAssertCtempTransform {
const unsupported_ctemp_assert_transform = IError(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 { match expr {
ast.CallExpr { ast.CallExpr {
return g.new_ctemp_var_then_gen(expr, expr_type) return g.new_ctemp_var_then_gen(expr, expr_type)

View File

@ -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 mut name := node.name
if name in ['+', '-', '*', '/', '%', '<', '=='] { if name in ['+', '-', '*', '/', '%', '<', '=='] {
name = util.replace_op(name) name = util.replace_op(name)
@ -425,7 +425,7 @@ fn (mut g Gen) c_fn_name(node &ast.FnDecl) ?string {
if node.is_method { if node.is_method {
unwrapped_rec_sym := g.table.sym(g.unwrap_generic(node.receiver.typ)) unwrapped_rec_sym := g.table.sym(g.unwrap_generic(node.receiver.typ))
if unwrapped_rec_sym.kind == .placeholder { if unwrapped_rec_sym.kind == .placeholder {
return none return error('none')
} }
name = g.cc_type(node.receiver.typ, false) + '_' + name name = g.cc_type(node.receiver.typ, false) + '_' + name
} }

View File

@ -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 { match name {
// platforms/os-es: // platforms/os-es:
'windows' { '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 error('bad os ifdef name "$name"') // should never happen, caught in the checker
} }
} }
return none return error('none')
} }

View File

@ -1075,7 +1075,7 @@ struct UnsupportedAssertCtempTransform {
const unsupported_ctemp_assert_transform = IError(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 { match expr {
ast.CallExpr { ast.CallExpr {
return g.new_ctemp_var_then_gen(expr, expr_type) return g.new_ctemp_var_then_gen(expr, expr_type)

View File

@ -35,7 +35,7 @@ fn test_node_exists() {
println('Using node version: $version') 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.setenv('VCOLORS', 'never', true)
os.chdir(vroot) or {} os.chdir(vroot) or {}
test_dir := 'vlib/v/gen/js/tests/testdata' test_dir := 'vlib/v/gen/js/tests/testdata'
@ -50,21 +50,21 @@ fn get_main_files_in_dir(dir string) []string {
return mfiles return mfiles
} }
fn check_path(dir string, tests []string) ?int { fn check_path(dir string, tests []string) !int {
mut nb_fail := 0 mut nb_fail := 0
paths := vtest.filter_vtest_only(tests, basepath: vroot) paths := vtest.filter_vtest_only(tests, basepath: vroot)
for path in paths { for path in paths {
program := path.replace(vroot + os.path_separator, '') program := path.replace(vroot + os.path_separator, '')
program_out := program.replace('.v', '.out') program_out := program.replace('.v', '.out')
if !os.exists(program_out) { if !os.exists(program_out) {
os.write_file(program_out, '')? os.write_file(program_out, '')!
} }
print(program + ' ') print(program + ' ')
res := os.execute('${os.quoted_path(vexe)} -b js_node run ${os.quoted_path(program)}') res := os.execute('${os.quoted_path(vexe)} -b js_node run ${os.quoted_path(program)}')
if res.exit_code < 0 { if res.exit_code < 0 {
panic(res.output) panic(res.output)
} }
mut expected := os.read_file(program_out)? mut expected := os.read_file(program_out)!
expected = clean_line_endings(expected) expected = clean_line_endings(expected)
found := clean_line_endings(res.output) found := clean_line_endings(res.output)
if expected != found { if expected != found {

View File

@ -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 { match arch {
.arm64 { .arm64 {
return Arm64{ return Arm64{

View File

@ -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() sw := time.new_stopwatch()
new_lib_path := compile_lib(mut r) or { return error('errors while compiling $r.original') } 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') elog(r, '> compile_and_reload_shared_lib compiled: $new_lib_path')

View File

@ -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)') p.trace_parser('expr($precedence)')
mut node := ast.empty_expr mut node := ast.empty_expr
is_stmt_ident := p.is_stmt_ident 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) { if p.tok.kind != .eof && !(p.tok.kind == .rsbr && p.inside_asm) {
// eof should be handled where it happens // eof should be handled where it happens
return none return error('none')
// return p.unexpected(prepend_msg: 'invalid expression: ') // return p.unexpected(prepend_msg: 'invalid expression: ')
} }
} }

View File

@ -584,7 +584,7 @@ run them via `v file.v` instead',
return fn_decl 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 p.inside_receiver_param = true
defer { defer {
p.inside_receiver_param = false p.inside_receiver_param = false

View File

@ -15,7 +15,7 @@ fn testsuite_end() {
os.rmdir_all(tfolder) or {} os.rmdir_all(tfolder) or {}
} }
fn test_cflags() ? { fn test_cflags() {
os.chdir(os.real_path(@VMODROOT)) or {} os.chdir(os.real_path(@VMODROOT)) or {}
mut debug_arg := '-g3 -O0' mut debug_arg := '-g3 -O0'
mut optimised_arg := '-O1' mut optimised_arg := '-O1'

View File

@ -32,7 +32,7 @@ pub enum OS {
} }
// Helper function to convert string names to OS enum // 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 { match os_str {
'' { '' {
return ._auto return ._auto

View File

@ -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'\-') 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 { match arch_str {
'amd64', 'x86_64', 'x64', 'x86' { // amd64 recommended '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) 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 { match s {
'c' { return .c } 'c' { return .c }
'js' { return .js_node } 'js' { return .js_node }

View File

@ -121,5 +121,5 @@ pub fn change_test_runner(x &TestRunner) {
// `vlib/sync/channel_close_test.v` compiles with simpler runners, // `vlib/sync/channel_close_test.v` compiles with simpler runners,
// that do not `import os` (which has other `fn()?`). Without it, // that do not `import os` (which has other `fn()?`). Without it,
// the C `Option_void` type is undefined -> C compilation error. // the C `Option_void` type is undefined -> C compilation error.
fn vtest_option_cludge() ? { fn vtest_option_cludge() ! {
} }

View File

@ -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 { return match s {
'unknown' { .unknown } 'unknown' { .unknown }
'eof' { .eof } 'eof' { .eof }

View File

@ -4,7 +4,7 @@ import v.util.diff
// iterates through a list of known diff cli commands // iterates through a list of known diff cli commands
// and returns it with basic options // 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() return diff.find_working_diff_command()
} }

View File

@ -5,7 +5,7 @@ import time
// iterates through a list of known diff cli commands // iterates through a list of known diff cli commands
// and returns it with basic options // 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_difftool := os.getenv('VDIFF_TOOL')
env_diffopts := os.getenv('VDIFF_OPTIONS') env_diffopts := os.getenv('VDIFF_OPTIONS')
if env_difftool != '' { if env_difftool != '' {

View File

@ -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 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 it leads to path differences, and the / version on windows triggers a module lookip bug,
// 2022-01-30 leading to completely different errors) // 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()` // TODO: explore using `pref.lookup_path` & `os.vmodules_paths()`
// absolute paths instead of 'vlib' & '.vmodules' // absolute paths instead of 'vlib' & '.vmodules'
mut vmod_folders := ['vlib', '.vmodules', 'modules'] mut vmod_folders := ['vlib', '.vmodules', 'modules']

View File

@ -62,7 +62,7 @@ pub fn set_vroot_folder(vroot_path string) {
os.setenv('VCHILD', 'true', true) 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() mut mcache := vmod.get_cache()
vmod_file_location := mcache.get_by_folder(dir) vmod_file_location := mcache.get_by_folder(dir)
if vmod_file_location.vmod_file.len == 0 { 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')` // resolve_env_value replaces all occurrences of `$env('ENV_VAR_NAME')`
// in `str` with the value of the env variable `$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('" env_ident := "\$env('"
at := str.index(env_ident) or { at := str.index(env_ident) or {
return error('no "$env_ident' + '...\')" could be found in "$str".') return error('no "$env_ident' + '...\')" could be found in "$str".')
@ -296,7 +296,7 @@ mut:
} }
[unsafe] [unsafe]
pub fn cached_read_source_file(path string) ?string { pub fn cached_read_source_file(path string) !string {
mut static cache := &SourceCache(0) mut static cache := &SourceCache(0)
if cache == unsafe { nil } { if cache == unsafe { nil } {
cache = &SourceCache{} cache = &SourceCache{}
@ -366,7 +366,7 @@ fn non_empty(arg []string) []string {
return arg.filter(it != '') 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) mpath := os.join_path_single(os.vmodules_dir(), modulename)
mod_v_file := os.join_path_single(mpath, 'v.mod') mod_v_file := os.join_path_single(mpath, 'v.mod')
murl := 'https://github.com/vlang/$modulename' 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 // 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 // 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. // 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{} mut files := []string{}
for file in roots { for file in roots {
if os.is_dir(file) { 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) } return unsafe { cached_read_source_file(file_path) }
} }

View File

@ -52,7 +52,7 @@ struct Token {
line int line int
} }
pub fn from_file(vmod_path string) ?Manifest { pub fn from_file(vmod_path string) !Manifest {
if !os.exists(vmod_path) { if !os.exists(vmod_path) {
return error('v.mod: v.mod file not found.') return error('v.mod: v.mod file not found.')
} }
@ -60,7 +60,7 @@ pub fn from_file(vmod_path string) ?Manifest {
return decode(contents) return decode(contents)
} }
pub fn decode(contents string) ?Manifest { pub fn decode(contents string) !Manifest {
mut parser := Parser{ mut parser := Parser{
scanner: Scanner{ scanner: Scanner{
pos: 0 pos: 0
@ -158,7 +158,7 @@ fn (mut s Scanner) scan_all() {
s.tokenize(.eof, 'eof') 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 vals := []string{}
mut idx := st_idx mut idx := st_idx
if tokens[idx].typ != .labr { if tokens[idx].typ != .labr {
@ -187,7 +187,7 @@ fn get_array_content(tokens []Token, st_idx int) ?([]string, int) {
return vals, idx return vals, idx
} }
fn (mut p Parser) parse() ?Manifest { fn (mut p Parser) parse() !Manifest {
if p.scanner.text.len == 0 { if p.scanner.text.len == 0 {
return error('$vmod.err_label no content.') return error('$vmod.err_label no content.')
} }
@ -237,14 +237,14 @@ fn (mut p Parser) parse() ?Manifest {
mn.author = field_value mn.author = field_value
} }
'dependencies' { 'dependencies' {
deps, idx := get_array_content(tokens, i + 1)? deps, idx := get_array_content(tokens, i + 1)!
mn.dependencies = deps mn.dependencies = deps
i = idx i = idx
continue continue
} }
else { else {
if tokens[i + 1].typ == .labr { 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 mn.unknown[field_name] = vals
i = idx i = idx
continue continue