diff --git a/vlib/builtin/array.v b/vlib/builtin/array.v index b2dee67c15..665f215ada 100644 --- a/vlib/builtin/array.v +++ b/vlib/builtin/array.v @@ -636,7 +636,7 @@ fn (mut a array) push(val voidptr) { // `val` is array.data and user facing usage is `a << [1,2,3]` [unsafe] pub fn (mut a3 array) push_many(val voidptr, size int) { - if size <= 0 || isnil(val) { + if size <= 0 || val == unsafe { nil } { return } a3.ensure_cap(a3.len + size) diff --git a/vlib/builtin/array_d_gcboehm_opt.v b/vlib/builtin/array_d_gcboehm_opt.v index 238b6300a2..9f8a5bab3e 100644 --- a/vlib/builtin/array_d_gcboehm_opt.v +++ b/vlib/builtin/array_d_gcboehm_opt.v @@ -227,7 +227,7 @@ fn (mut a array) push_noscan(val voidptr) { // `val` is array.data and user facing usage is `a << [1,2,3]` [unsafe] fn (mut a3 array) push_many_noscan(val voidptr, size int) { - if size <= 0 || isnil(val) { + if size <= 0 || val == unsafe { nil } { return } if a3.data == val && a3.data != 0 { diff --git a/vlib/builtin/builtin_d_use_libbacktrace.c.v b/vlib/builtin/builtin_d_use_libbacktrace.c.v index d4f344fc18..90f2688b42 100644 --- a/vlib/builtin/builtin_d_use_libbacktrace.c.v +++ b/vlib/builtin/builtin_d_use_libbacktrace.c.v @@ -38,8 +38,12 @@ struct BacktraceOptions { } fn bt_print_callback(data &BacktraceOptions, pc voidptr, filename_ptr &char, line int, fn_name_ptr &char) int { - filename := if isnil(filename_ptr) { '???' } else { unsafe { filename_ptr.vstring() } } - fn_name := if isnil(fn_name_ptr) { + filename := if filename_ptr == unsafe { nil } { + '???' + } else { + unsafe { filename_ptr.vstring() } + } + fn_name := if fn_name_ptr == unsafe { nil } { '???' } else { (unsafe { fn_name_ptr.vstring() }).replace('__', '.') @@ -56,7 +60,7 @@ fn bt_print_callback(data &BacktraceOptions, pc voidptr, filename_ptr &char, lin } fn bt_error_callback(data voidptr, msg_ptr &char, errnum int) { - // if !isnil(data) && !isnil(data.state) && !isnil(data.state.filename) { + // if data != unsafe { nil } && data.state != unsafe { nil } && data.state.filename != unsafe { nil } { // filename := unsafe{ data.state.filename.vstring() } // eprint('$filename: ') // } diff --git a/vlib/builtin/builtin_nix.c.v b/vlib/builtin/builtin_nix.c.v index 539ecbe217..871dc84428 100644 --- a/vlib/builtin/builtin_nix.c.v +++ b/vlib/builtin/builtin_nix.c.v @@ -96,7 +96,7 @@ fn print_backtrace_skipping_top_frames_linux(skipframes int) bool { cmd := 'addr2line -e $executable $addr' // taken from os, to avoid depending on the os module inside builtin.v f := C.popen(&char(cmd.str), c'r') - if isnil(f) { + if f == unsafe { nil } { eprintln(sframe) continue } diff --git a/vlib/builtin/sorted_map.v b/vlib/builtin/sorted_map.v index 7893ad00c7..ec90dcada2 100644 --- a/vlib/builtin/sorted_map.v +++ b/vlib/builtin/sorted_map.v @@ -73,7 +73,7 @@ fn (mut m SortedMap) set(key string, value voidptr) { mut parent := &mapnode(0) for { if node.len == max_len { - if isnil(parent) { + if parent == unsafe { nil } { parent = new_node() m.root = parent } @@ -100,7 +100,7 @@ fn (mut m SortedMap) set(key string, value voidptr) { } return } - if isnil(node.children) { + if node.children == unsafe { nil } { mut j := node.len - 1 for j >= 0 && key < node.keys[j] { node.keys[j + 1] = node.keys[j] @@ -130,7 +130,7 @@ fn (mut n mapnode) split_child(child_index int, mut y mapnode) { z.keys[j] = y.keys[j + degree] z.values[j] = y.values[j + degree] } - if !isnil(y.children) { + if y.children != unsafe { nil } { z.children = unsafe { &voidptr(malloc(int(children_bytes))) } for jj := degree - 1; jj >= 0; jj-- { unsafe { @@ -139,7 +139,7 @@ fn (mut n mapnode) split_child(child_index int, mut y mapnode) { } } unsafe { - if isnil(n.children) { + if n.children == nil { n.children = &voidptr(malloc(int(children_bytes))) } n.children[n.len + 1] = n.children[n.len] @@ -173,7 +173,7 @@ fn (m SortedMap) get(key string, out voidptr) bool { } return true } - if isnil(node.children) { + if node.children == unsafe { nil } { break } node = unsafe { &mapnode(node.children[i + 1]) } @@ -182,7 +182,7 @@ fn (m SortedMap) get(key string, out voidptr) bool { } fn (m SortedMap) exists(key string) bool { - if isnil(m.root) { // TODO: find out why root can be nil + if m.root == unsafe { nil } { // TODO: find out why root can be nil return false } mut node := m.root @@ -194,7 +194,7 @@ fn (m SortedMap) exists(key string) bool { if i != -1 && key == node.keys[i] { return true } - if isnil(node.children) { + if node.children == unsafe { nil } { break } node = unsafe { &mapnode(node.children[i + 1]) } @@ -213,14 +213,14 @@ fn (n &mapnode) find_key(k string) int { fn (mut n mapnode) remove_key(k string) bool { idx := n.find_key(k) if idx < n.len && n.keys[idx] == k { - if isnil(n.children) { + if n.children == unsafe { nil } { n.remove_from_leaf(idx) } else { n.remove_from_non_leaf(idx) } return true } else { - if isnil(n.children) { + if n.children == unsafe { nil } { return false } flag := if idx == n.len { true } else { false } @@ -250,7 +250,7 @@ fn (mut n mapnode) remove_from_non_leaf(idx int) { k := n.keys[idx] if unsafe { &mapnode(n.children[idx]) }.len >= degree { mut current := unsafe { &mapnode(n.children[idx]) } - for !isnil(current.children) { + for current.children != unsafe { nil } { current = unsafe { &mapnode(current.children[current.len]) } } predecessor := current.keys[current.len - 1] @@ -260,7 +260,7 @@ fn (mut n mapnode) remove_from_non_leaf(idx int) { node.remove_key(predecessor) } else if unsafe { &mapnode(n.children[idx + 1]) }.len >= degree { mut current := unsafe { &mapnode(n.children[idx + 1]) } - for !isnil(current.children) { + for current.children != unsafe { nil } { current = unsafe { &mapnode(current.children[0]) } } successor := current.keys[0] @@ -294,7 +294,7 @@ fn (mut n mapnode) borrow_from_prev(idx int) { child.keys[i + 1] = child.keys[i] child.values[i + 1] = child.values[i] } - if !isnil(child.children) { + if child.children != unsafe { nil } { for i := child.len; i >= 0; i-- { unsafe { child.children[i + 1] = child.children[i] @@ -303,7 +303,7 @@ fn (mut n mapnode) borrow_from_prev(idx int) { } child.keys[0] = n.keys[idx - 1] child.values[0] = n.values[idx - 1] - if !isnil(child.children) { + if child.children != unsafe { nil } { unsafe { child.children[0] = sibling.children[sibling.len] } @@ -319,7 +319,7 @@ fn (mut n mapnode) borrow_from_next(idx int) { mut sibling := unsafe { &mapnode(n.children[idx + 1]) } child.keys[child.len] = n.keys[idx] child.values[child.len] = n.values[idx] - if !isnil(child.children) { + if child.children != unsafe { nil } { unsafe { child.children[child.len + 1] = sibling.children[0] } @@ -330,7 +330,7 @@ fn (mut n mapnode) borrow_from_next(idx int) { sibling.keys[i - 1] = sibling.keys[i] sibling.values[i - 1] = sibling.values[i] } - if !isnil(sibling.children) { + if sibling.children != unsafe { nil } { for i := 1; i <= sibling.len; i++ { unsafe { sibling.children[i - 1] = sibling.children[i] @@ -350,7 +350,7 @@ fn (mut n mapnode) merge(idx int) { child.keys[i + degree] = sibling.keys[i] child.values[i + degree] = sibling.values[i] } - if !isnil(child.children) { + if child.children != unsafe { nil } { for i := 0; i <= sibling.len; i++ { unsafe { child.children[i + degree] = sibling.children[i] @@ -383,7 +383,7 @@ pub fn (mut m SortedMap) delete(key string) { if m.root.len == 0 { // tmp := t.root - if isnil(m.root.children) { + if m.root.children == unsafe { nil } { return } else { m.root = unsafe { &mapnode(m.root.children[0]) } @@ -396,7 +396,7 @@ pub fn (mut m SortedMap) delete(key string) { // starting at `at`. Keys are inserted in order. fn (n &mapnode) subkeys(mut keys []string, at int) int { mut position := at - if !isnil(n.children) { + if n.children != unsafe { nil } { // Traverse children and insert // keys inbetween children for i in 0 .. n.len { @@ -421,7 +421,7 @@ fn (n &mapnode) subkeys(mut keys []string, at int) int { pub fn (m &SortedMap) keys() []string { mut keys := []string{len: m.len} - if isnil(m.root) || m.root.len == 0 { + if m.root == unsafe { nil } || m.root.len == 0 { return keys } m.root.subkeys(mut keys, 0) @@ -433,7 +433,7 @@ fn (mut n mapnode) free() { } pub fn (mut m SortedMap) free() { - if isnil(m.root) { + if m.root == unsafe { nil } { return } m.root.free() diff --git a/vlib/darwin/darwin.v b/vlib/darwin/darwin.v index b85d8d71e9..36c72659b6 100644 --- a/vlib/darwin/darwin.v +++ b/vlib/darwin/darwin.v @@ -38,7 +38,7 @@ fn C.CFRelease(url &u8) pub fn resource_path() string { main_bundle := C.CFBundleGetMainBundle() resource_dir_url := C.CFBundleCopyResourcesDirectoryURL(main_bundle) - if isnil(resource_dir_url) { + if resource_dir_url == unsafe { nil } { panic('CFBundleCopyResourcesDirectoryURL failed') } buffer_size := 4096 diff --git a/vlib/gg/gg.c.v b/vlib/gg/gg.c.v index 380283c207..a4c1e2f54b 100644 --- a/vlib/gg/gg.c.v +++ b/vlib/gg/gg.c.v @@ -421,7 +421,7 @@ pub fn new_context(cfg Config) &Context { ui_mode: cfg.ui_mode native_rendering: cfg.native_rendering } - if isnil(cfg.user_data) { + if cfg.user_data == unsafe { nil } { ctx.user_data = ctx } ctx.set_bg_color(cfg.bg_color) diff --git a/vlib/gx/image.v b/vlib/gx/image.v index 4a20ea1fd0..890e516a0d 100644 --- a/vlib/gx/image.v +++ b/vlib/gx/image.v @@ -10,5 +10,5 @@ pub: } pub fn (i Image) is_empty() bool { - return isnil(i.obj) + return i.obj == unsafe { nil } } diff --git a/vlib/sync/pool/pool.v b/vlib/sync/pool/pool.v index 4727055b80..1ac7514347 100644 --- a/vlib/sync/pool/pool.v +++ b/vlib/sync/pool/pool.v @@ -42,7 +42,7 @@ pub struct PoolProcessorConfig { // 3) task_id - the index of the worker thread in which the callback // function is running. pub fn new_pool_processor(context PoolProcessorConfig) &PoolProcessor { - if isnil(context.callback) { + if context.callback == unsafe { nil } { panic('You need to pass a valid callback to new_pool_processor.') } mut pool := PoolProcessor{ diff --git a/vlib/v/ast/scope.v b/vlib/v/ast/scope.v index 47f4e5da51..3722a7275d 100644 --- a/vlib/v/ast/scope.v +++ b/vlib/v/ast/scope.v @@ -38,7 +38,7 @@ pub fn new_scope(parent &Scope, start_pos int) &Scope { */ fn (s &Scope) dont_lookup_parent() bool { - return isnil(s.parent) || s.detached_from_parent + return s.parent == unsafe { nil } || s.detached_from_parent } pub fn (s &Scope) find(name string) ?ScopeObject { diff --git a/vlib/v/builder/msvc_windows.v b/vlib/v/builder/msvc_windows.v index a76b412c7c..0604624a95 100644 --- a/vlib/v/builder/msvc_windows.v +++ b/vlib/v/builder/msvc_windows.v @@ -34,7 +34,7 @@ fn find_windows_kit_internal(key RegKey, versions []string) ?string { } alloc_length := (required_bytes + 2) mut value := &u16(malloc_noscan(int(alloc_length))) - if isnil(value) { + if value == nil { continue } // diff --git a/vlib/v/checker/check_types.v b/vlib/v/checker/check_types.v index b74aae40bf..bc28a80d6e 100644 --- a/vlib/v/checker/check_types.v +++ b/vlib/v/checker/check_types.v @@ -651,7 +651,8 @@ pub fn (mut c Checker) infer_fn_generic_types(func ast.Fn, mut node ast.CallExpr } else { match sym.info { ast.Struct, ast.Interface, ast.SumType { - if !isnil(c.table.cur_fn) && c.table.cur_fn.generic_names.len > 0 { // in generic fn + if c.table.cur_fn != unsafe { nil } + && c.table.cur_fn.generic_names.len > 0 { // in generic fn if gt_name in c.table.cur_fn.generic_names && c.table.cur_fn.generic_names.len == c.table.cur_concrete_types.len { idx := c.table.cur_fn.generic_names.index(gt_name) @@ -704,7 +705,7 @@ pub fn (mut c Checker) infer_fn_generic_types(func ast.Fn, mut node ast.CallExpr mut param_elem_sym := c.table.sym(param_elem_info.elem_type) for { if arg_elem_sym.kind == .array && param_elem_sym.kind == .array - && !isnil(c.table.cur_fn) + && c.table.cur_fn != unsafe { nil } && param_elem_sym.name !in c.table.cur_fn.generic_names { arg_elem_info = arg_elem_sym.info as ast.Array arg_elem_sym = c.table.sym(arg_elem_info.elem_type) @@ -724,7 +725,7 @@ pub fn (mut c Checker) infer_fn_generic_types(func ast.Fn, mut node ast.CallExpr mut param_elem_sym := c.table.sym(param_elem_info.elem_type) for { if arg_elem_sym.kind == .array_fixed && param_elem_sym.kind == .array_fixed - && !isnil(c.table.cur_fn) + && c.table.cur_fn != unsafe { nil } && param_elem_sym.name !in c.table.cur_fn.generic_names { arg_elem_info = arg_elem_sym.info as ast.ArrayFixed arg_elem_sym = c.table.sym(arg_elem_info.elem_type) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 029b9bbd36..d003e6da1d 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -955,7 +955,7 @@ pub fn (mut c Checker) check_expr_opt_call(expr ast.Expr, ret_type ast.Type) ast pub fn (mut c Checker) check_or_expr(node ast.OrExpr, ret_type ast.Type, expr_return_type ast.Type) { if node.kind == .propagate_option { - if !isnil(c.table.cur_fn) && !c.table.cur_fn.return_type.has_flag(.optional) + if c.table.cur_fn != unsafe { nil } && !c.table.cur_fn.return_type.has_flag(.optional) && c.table.cur_fn.name != 'main.main' && !c.inside_const { c.error('to propagate the call, `$c.table.cur_fn.name` must return an optional type', node.pos) @@ -972,7 +972,7 @@ pub fn (mut c Checker) check_or_expr(node ast.OrExpr, ret_type ast.Type, expr_re return } if node.kind == .propagate_result { - if !isnil(c.table.cur_fn) && !c.table.cur_fn.return_type.has_flag(.result) + if c.table.cur_fn != unsafe { nil } && !c.table.cur_fn.return_type.has_flag(.result) && c.table.cur_fn.name != 'main.main' && !c.inside_const { c.error('to propagate the call, `$c.table.cur_fn.name` must return an result type', node.pos) @@ -1093,7 +1093,7 @@ pub fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type { match mut node.expr { ast.Ident { name := node.expr.name - valid_generic := util.is_generic_type_name(name) && !isnil(c.table.cur_fn) + valid_generic := util.is_generic_type_name(name) && c.table.cur_fn != unsafe { nil } && name in c.table.cur_fn.generic_names if valid_generic { name_type = ast.Type(c.table.find_type_idx(name)).set_flag(.generic) @@ -1497,7 +1497,7 @@ fn (mut c Checker) stmt(node_ ast.Stmt) { c.inside_const = false } ast.DeferStmt { - if node.idx_in_fn < 0 && !isnil(c.table.cur_fn) { + if node.idx_in_fn < 0 && c.table.cur_fn != unsafe { nil } { node.idx_in_fn = c.table.cur_fn.defer_stmts.len c.table.cur_fn.defer_stmts << unsafe { &node } } @@ -2035,7 +2035,7 @@ fn (mut c Checker) stmts_ending_with_expression(stmts []ast.Stmt) { } pub fn (mut c Checker) unwrap_generic(typ ast.Type) ast.Type { - if typ.has_flag(.generic) && !isnil(c.table.cur_fn) { + if typ.has_flag(.generic) && c.table.cur_fn != unsafe { nil } { if t_typ := c.table.resolve_generic_to_concrete(typ, c.table.cur_fn.generic_names, c.table.cur_concrete_types) { @@ -2629,13 +2629,13 @@ pub fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type { fn (mut c Checker) at_expr(mut node ast.AtExpr) ast.Type { match node.kind { .fn_name { - if isnil(c.table.cur_fn) { + if c.table.cur_fn == unsafe { nil } { return ast.void_type } node.val = c.table.cur_fn.name.all_after_last('.') } .method_name { - if isnil(c.table.cur_fn) { + if c.table.cur_fn == unsafe { nil } { return ast.void_type } fname := c.table.cur_fn.name.all_after_last('.') @@ -2647,7 +2647,7 @@ fn (mut c Checker) at_expr(mut node ast.AtExpr) ast.Type { } } .mod_name { - if isnil(c.table.cur_fn) { + if c.table.cur_fn == unsafe { nil } { return ast.void_type } node.val = c.table.cur_fn.mod @@ -3976,7 +3976,7 @@ pub fn (mut c Checker) goto_stmt(node ast.GotoStmt) { if !c.inside_unsafe { c.warn('`goto` requires `unsafe` (consider using labelled break/continue)', node.pos) } - if !isnil(c.table.cur_fn) && node.name !in c.table.cur_fn.label_names { + if c.table.cur_fn != unsafe { nil } && node.name !in c.table.cur_fn.label_names { c.error('unknown label `$node.name`', node.pos) } c.goto_labels[node.name]++ // Register a label use diff --git a/vlib/v/checker/comptime.v b/vlib/v/checker/comptime.v index 3e2d5e8709..0b4ef8534c 100644 --- a/vlib/v/checker/comptime.v +++ b/vlib/v/checker/comptime.v @@ -365,7 +365,7 @@ fn (mut c Checker) verify_all_vweb_routes() { is_ok, nroute_attributes, nargs := c.verify_vweb_params_for_method(m) if !is_ok { f := &ast.FnDecl(m.source_fn) - if isnil(f) { + if f == unsafe { nil } { continue } if f.return_type == typ_vweb_result && f.receiver.typ == m.params[0].typ diff --git a/vlib/v/checker/containers.v b/vlib/v/checker/containers.v index dbc51a8546..f29924c468 100644 --- a/vlib/v/checker/containers.v +++ b/vlib/v/checker/containers.v @@ -77,7 +77,7 @@ pub fn (mut c Checker) array_init(mut node ast.ArrayInit) ast.Type { c.ensure_sumtype_array_has_default_value(node) } c.ensure_type_exists(node.elem_type, node.elem_type_pos) or {} - if node.typ.has_flag(.generic) && !isnil(c.table.cur_fn) + if node.typ.has_flag(.generic) && c.table.cur_fn != unsafe { nil } && c.table.cur_fn.generic_names.len == 0 { c.error('generic struct cannot be used in non-generic function', node.pos) } diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index e3b85930d9..7bd0c7de29 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -460,7 +460,7 @@ pub fn (mut c Checker) call_expr(mut node ast.CallExpr) ast.Type { c.expected_or_type = node.return_type.clear_flag(.optional) c.stmts_ending_with_expression(node.or_block.stmts) c.expected_or_type = ast.void_type - if node.or_block.kind == .propagate_option && !isnil(c.table.cur_fn) + if node.or_block.kind == .propagate_option && c.table.cur_fn != unsafe { nil } && !c.table.cur_fn.return_type.has_flag(.optional) && !c.inside_const { if !c.table.cur_fn.is_main { c.error('to propagate the optional call, `$c.table.cur_fn.name` must return an optional', @@ -486,7 +486,7 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) concrete_types << concrete_type } } - if !isnil(c.table.cur_fn) && c.table.cur_concrete_types.len == 0 && has_generic { + if c.table.cur_fn != unsafe { nil } && c.table.cur_concrete_types.len == 0 && has_generic { c.error('generic fn using generic types cannot be called outside of generic fn', node.pos) } @@ -521,7 +521,7 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) c.error('JS.await: first argument must be a promise, got `$tsym.name`', node.pos) return ast.void_type } - if !isnil(c.table.cur_fn) { + if c.table.cur_fn != unsafe { nil } { c.table.cur_fn.has_await = true } match tsym.info { @@ -787,7 +787,7 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) && func.mod != c.mod && !c.pref.is_test { c.error('function `$func.name` is private', node.pos) } - if !isnil(c.table.cur_fn) && !c.table.cur_fn.is_deprecated && func.is_deprecated { + if c.table.cur_fn != unsafe { nil } && !c.table.cur_fn.is_deprecated && func.is_deprecated { c.deprecate('function', func.name, func.attrs, node.pos) } if func.is_unsafe && !c.inside_unsafe @@ -1129,14 +1129,14 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) } } // resolve return generics struct to concrete type - if func.generic_names.len > 0 && func.return_type.has_flag(.generic) && !isnil(c.table.cur_fn) - && c.table.cur_fn.generic_names.len == 0 { + if func.generic_names.len > 0 && func.return_type.has_flag(.generic) + && c.table.cur_fn != unsafe { nil } && c.table.cur_fn.generic_names.len == 0 { node.return_type = c.table.unwrap_generic_type(func.return_type, func.generic_names, concrete_types) } else { node.return_type = func.return_type } - if node.concrete_types.len > 0 && func.return_type != 0 && !isnil(c.table.cur_fn) + if node.concrete_types.len > 0 && func.return_type != 0 && c.table.cur_fn != unsafe { nil } && c.table.cur_fn.generic_names.len == 0 { if typ := c.table.resolve_generic_to_concrete(func.return_type, func.generic_names, concrete_types) @@ -1183,7 +1183,7 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type { node.return_type = left_type node.receiver_type = left_type - if !isnil(c.table.cur_fn) && c.table.cur_fn.generic_names.len > 0 { + if c.table.cur_fn != unsafe { nil } && c.table.cur_fn.generic_names.len > 0 { c.table.unwrap_generic_type(left_type, c.table.cur_fn.generic_names, c.table.cur_concrete_types) } unwrapped_left_type := c.unwrap_generic(left_type) @@ -1262,7 +1262,7 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type { if node.args.len > 0 { c.error('wait() does not have any arguments', node.args[0].pos) } - if !isnil(c.table.cur_fn) { + if c.table.cur_fn != unsafe { nil } { c.table.cur_fn.has_await = true } node.return_type = info.concrete_types[0] @@ -1569,7 +1569,7 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type { c.warn('method `${left_sym.name}.$method_name` must be called from an `unsafe` block', node.pos) } - if !isnil(c.table.cur_fn) && !c.table.cur_fn.is_deprecated && method.is_deprecated { + if c.table.cur_fn != unsafe { nil } && !c.table.cur_fn.is_deprecated && method.is_deprecated { c.deprecate('method', '${left_sym.name}.$method.name', method.attrs, node.pos) } c.set_node_expected_arg_types(mut node, method) @@ -1593,7 +1593,7 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type { // resolve return generics struct to concrete type if method.generic_names.len > 0 && method.return_type.has_flag(.generic) - && !isnil(c.table.cur_fn) && c.table.cur_fn.generic_names.len == 0 { + && c.table.cur_fn != unsafe { nil } && c.table.cur_fn.generic_names.len == 0 { node.return_type = c.table.unwrap_generic_type(method.return_type, method.generic_names, concrete_types) } else { diff --git a/vlib/v/checker/return.v b/vlib/v/checker/return.v index cd7f27246e..1711bbab2e 100644 --- a/vlib/v/checker/return.v +++ b/vlib/v/checker/return.v @@ -7,7 +7,7 @@ import v.pref // TODO: non deferred pub fn (mut c Checker) return_stmt(mut node ast.Return) { - if isnil(c.table.cur_fn) { + if c.table.cur_fn == unsafe { nil } { return } c.expected_type = c.table.cur_fn.return_type diff --git a/vlib/v/checker/str.v b/vlib/v/checker/str.v index de4cdc26bb..1a3816419e 100644 --- a/vlib/v/checker/str.v +++ b/vlib/v/checker/str.v @@ -104,8 +104,8 @@ pub fn (mut c Checker) string_inter_lit(mut node ast.StringInterLiteral) ast.Typ node.need_fmts[i] = fmt != c.get_default_fmt(ftyp, typ) } // check recursive str - if !isnil(c.table.cur_fn) && c.table.cur_fn.is_method && c.table.cur_fn.name == 'str' - && c.table.cur_fn.receiver.name == expr.str() { + if c.table.cur_fn != unsafe { nil } && c.table.cur_fn.is_method + && c.table.cur_fn.name == 'str' && c.table.cur_fn.receiver.name == expr.str() { c.error('cannot call `str()` method recursively', expr.pos()) } } diff --git a/vlib/v/checker/struct.v b/vlib/v/checker/struct.v index 6de21c0425..d0eff93a73 100644 --- a/vlib/v/checker/struct.v +++ b/vlib/v/checker/struct.v @@ -244,7 +244,7 @@ pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type { && node.generic_types.len != struct_sym.info.generic_types.len { c.error('generic struct init expects $struct_sym.info.generic_types.len generic parameter, but got $node.generic_types.len', node.pos) - } else if node.generic_types.len > 0 && !isnil(c.table.cur_fn) { + } else if node.generic_types.len > 0 && c.table.cur_fn != unsafe { nil } { for gtyp in node.generic_types { gtyp_name := c.table.sym(gtyp).name if gtyp_name !in c.table.cur_fn.generic_names { @@ -276,7 +276,7 @@ pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type { } } // register generic struct type when current fn is generic fn - if !isnil(c.table.cur_fn) && c.table.cur_fn.generic_names.len > 0 { + if c.table.cur_fn != unsafe { nil } && c.table.cur_fn.generic_names.len > 0 { c.table.unwrap_generic_type(node.typ, c.table.cur_fn.generic_names, c.table.cur_concrete_types) } c.ensure_type_exists(node.typ, node.pos) or {} @@ -321,7 +321,8 @@ pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type { 'it cannot be initialized with `$type_sym.name{}`', node.pos) } } - if type_sym.name.len == 1 && !isnil(c.table.cur_fn) && c.table.cur_fn.generic_names.len == 0 { + if type_sym.name.len == 1 && c.table.cur_fn != unsafe { nil } + && c.table.cur_fn.generic_names.len == 0 { c.error('unknown struct `$type_sym.name`', node.pos) return ast.void_type } diff --git a/vlib/v/embed_file/embed_file.v b/vlib/v/embed_file/embed_file.v index b6366f585a..271739c476 100644 --- a/vlib/v/embed_file/embed_file.v +++ b/vlib/v/embed_file/embed_file.v @@ -59,10 +59,10 @@ pub fn (original &EmbedFileData) to_bytes() []u8 { } pub fn (mut ed EmbedFileData) data() &u8 { - if !isnil(ed.uncompressed) { + if ed.uncompressed != unsafe { nil } { return ed.uncompressed } - if isnil(ed.uncompressed) && !isnil(ed.compressed) { + if ed.uncompressed == unsafe { nil } && ed.compressed != unsafe { nil } { decoder := g_embed_file_decoders.decoders[ed.compression_type] or { panic('EmbedFileData error: unknown compression of "$ed.path": "$ed.compression_type"') } diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 7010092693..8d68daeae5 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -1903,7 +1903,7 @@ pub fn (mut f Fmt) ident(node ast.Ident) { f.write('_') } else { mut is_local := false - if !isnil(f.fn_scope) { + if f.fn_scope != unsafe { nil } { if _ := f.fn_scope.find_var(node.name) { is_local = true } diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 884b90a48c..b6af564cb2 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -2737,7 +2737,7 @@ fn (mut g Gen) trace_autofree(line string) { // fn (mut g Gen) autofree_scope_vars2(scope &ast.Scope, end_pos int) { fn (mut g Gen) autofree_scope_vars2(scope &ast.Scope, start_pos int, end_pos int, line_nr int, free_parent_scopes bool, stop_pos int) { - if isnil(scope) { + if scope == unsafe { nil } { return } for _, obj in scope.objects { @@ -2793,8 +2793,8 @@ fn (mut g Gen) autofree_scope_vars2(scope &ast.Scope, start_pos int, end_pos int // return // } // ``` - // if !isnil(scope.parent) && line_nr > 0 { - if free_parent_scopes && !isnil(scope.parent) && !scope.detached_from_parent + // if scope.parent != unsafe { nil } && line_nr > 0 { + if free_parent_scopes && scope.parent != unsafe { nil } && !scope.detached_from_parent && (stop_pos == -1 || scope.parent.start_pos >= stop_pos) { g.trace_autofree('// af parent scope:') g.autofree_scope_vars2(scope.parent, start_pos, end_pos, line_nr, true, stop_pos) @@ -4239,7 +4239,7 @@ fn (mut g Gen) return_stmt(node ast.Return) { ftyp := g.typ(node.types[0]) mut is_regular_option := ftyp == '_option' if optional_none || is_regular_option || node.types[0] == ast.error_type_idx { - if !isnil(g.fn_decl) && g.fn_decl.is_test { + if g.fn_decl != unsafe { nil } && g.fn_decl.is_test { test_error_var := g.new_tmp_var() g.write('$ret_typ $test_error_var = ') g.gen_optional_error(g.fn_decl.return_type, node.exprs[0]) @@ -4267,7 +4267,7 @@ fn (mut g Gen) return_stmt(node ast.Return) { ftyp := g.typ(node.types[0]) mut is_regular_result := ftyp == c.result_name if is_regular_result || node.types[0] == ast.error_type_idx { - if !isnil(g.fn_decl) && g.fn_decl.is_test { + if g.fn_decl != unsafe { nil } && g.fn_decl.is_test { test_error_var := g.new_tmp_var() g.write('$ret_typ $test_error_var = ') g.gen_result_error(g.fn_decl.return_type, node.exprs[0]) @@ -5404,7 +5404,7 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type ast.Ty g.or_expr_return_type = ast.void_type } else if or_block.kind == .propagate_result || (or_block.kind == .propagate_option && return_type.has_flag(.result)) { - if g.file.mod.name == 'main' && (isnil(g.fn_decl) || g.fn_decl.is_main) { + if g.file.mod.name == 'main' && (g.fn_decl == unsafe { nil } || g.fn_decl.is_main) { // In main(), an `opt()!` call is sugar for `opt() or { panic(err) }` err_msg := 'IError_name_table[${cvar_name}.err._typ]._method_msg(${cvar_name}.err._object)' if g.pref.is_debug { @@ -5413,7 +5413,7 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type ast.Ty } else { g.writeln('\tpanic_result_not_set($err_msg);') } - } else if !isnil(g.fn_decl) && g.fn_decl.is_test { + } else if g.fn_decl != unsafe { nil } && g.fn_decl.is_test { g.gen_failing_error_propagation_for_test_fn(or_block, cvar_name) } else { // In ordinary functions, `opt()!` call is sugar for: @@ -5433,7 +5433,7 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type ast.Ty } } } else if or_block.kind == .propagate_option { - if g.file.mod.name == 'main' && (isnil(g.fn_decl) || g.fn_decl.is_main) { + if g.file.mod.name == 'main' && (g.fn_decl == unsafe { nil } || g.fn_decl.is_main) { // In main(), an `opt()?` call is sugar for `opt() or { panic(err) }` err_msg := 'IError_name_table[${cvar_name}.err._typ]._method_msg(${cvar_name}.err._object)' if g.pref.is_debug { @@ -5442,7 +5442,7 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type ast.Ty } else { g.writeln('\tpanic_optional_not_set( $err_msg );') } - } else if !isnil(g.fn_decl) && g.fn_decl.is_test { + } else if g.fn_decl != unsafe { nil } && g.fn_decl.is_test { g.gen_failing_error_propagation_for_test_fn(or_block, cvar_name) } else { // In ordinary functions, `opt()?` call is sugar for: @@ -6078,7 +6078,7 @@ static inline __shared__$interface_name ${shared_fn_name}(__shared__$cctype* x) fn (mut g Gen) panic_debug_info(pos token.Pos) (int, string, string, string) { paline := pos.line_nr + 1 - if isnil(g.fn_decl) { + if g.fn_decl == unsafe { nil } { return paline, '', 'main', 'C._vinit' } pafile := g.fn_decl.file.replace('\\', '/') diff --git a/vlib/v/util/util.v b/vlib/v/util/util.v index 2deee678f7..554698893e 100644 --- a/vlib/v/util/util.v +++ b/vlib/v/util/util.v @@ -295,7 +295,7 @@ mut: [unsafe] pub fn cached_read_source_file(path string) ?string { mut static cache := &SourceCache(0) - if isnil(cache) { + if cache == unsafe { nil } { cache = &SourceCache{} }