ast: define 'const invalid_type_idx = -1' (#13573)

pull/13585/head
yuyi 2022-02-23 16:54:43 +08:00 committed by GitHub
parent c3ec738126
commit b5e7cef1b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 10 deletions

View File

@ -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]

View File

@ -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 }

View File

@ -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{

View File

@ -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{}