diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index fdb4470b1c..a2440c4668 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -69,6 +69,8 @@ pub fn (mut t Table) free() { } } +pub const invalid_type_idx = -1 + pub type FnPanicHandler = fn (&Table, string) fn default_table_panic_handler(t &Table, message string) { @@ -685,8 +687,8 @@ pub fn (t &Table) find_sym_and_type_idx(name string) (&TypeSymbol, int) { } pub const invalid_type_symbol = &TypeSymbol{ - idx: -1 - parent_idx: -1 + idx: invalid_type_idx + parent_idx: invalid_type_idx language: .v mod: 'builtin' kind: .placeholder @@ -786,7 +788,7 @@ fn (mut t Table) rewrite_already_registered_symbol(typ TypeSymbol, existing_idx } return existing_idx } - return -1 + return ast.invalid_type_idx } [inline] diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 352b4e3725..994b65c03b 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -697,7 +697,8 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) node.pos) return func.return_type } - if func.return_type == ast.void_type && func.is_conditional && func.ctdefine_idx != -1 { + if func.return_type == ast.void_type && func.is_conditional + && func.ctdefine_idx != ast.invalid_type_idx { node.should_be_skipped = c.evaluate_once_comptime_if_attribute(mut func.attrs[func.ctdefine_idx]) } // dont check number of args for JS functions since arguments are not required @@ -1203,7 +1204,8 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type { && method.language == .v && method.no_body { c.error('cannot call a method that does not have a body', node.pos) } - if method.return_type == ast.void_type && method.is_conditional && method.ctdefine_idx != -1 { + if method.return_type == ast.void_type && method.is_conditional + && method.ctdefine_idx != ast.invalid_type_idx { node.should_be_skipped = c.evaluate_once_comptime_if_attribute(mut method.attrs[method.ctdefine_idx]) } c.check_expected_arg_count(mut node, method) or { return method.return_type } diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 0adf77053c..8a09e9e20c 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -402,7 +402,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl { receiver_type: rec.typ // attrs: p.attrs - is_conditional: conditional_ctdefine_idx != -1 + is_conditional: conditional_ctdefine_idx != ast.invalid_type_idx ctdefine_idx: conditional_ctdefine_idx // no_body: no_body @@ -451,7 +451,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl { is_method: false // attrs: p.attrs - is_conditional: conditional_ctdefine_idx != -1 + is_conditional: conditional_ctdefine_idx != ast.invalid_type_idx ctdefine_idx: conditional_ctdefine_idx // no_body: no_body @@ -506,7 +506,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl { is_markused: is_markused // attrs: p.attrs - is_conditional: conditional_ctdefine_idx != -1 + is_conditional: conditional_ctdefine_idx != ast.invalid_type_idx ctdefine_idx: conditional_ctdefine_idx // receiver: ast.StructField{ diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 3fcfe4815a..434082de31 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -3614,7 +3614,7 @@ fn (mut p Parser) type_decl() ast.TypeDecl { } is_public: is_pub }) - if typ == -1 { + if typ == ast.invalid_type_idx { p.error_with_pos('cannot register sum type `$name`, another type with this name exists', name_pos) return ast.SumTypeDecl{} @@ -3655,7 +3655,7 @@ fn (mut p Parser) type_decl() ast.TypeDecl { is_public: is_pub }) type_end_pos := p.prev_tok.pos() - if idx == -1 { + if idx == ast.invalid_type_idx { p.error_with_pos('cannot register alias `$name`, another type with this name exists', name_pos) return ast.AliasTypeDecl{}