ast: define 'const invalid_type_idx = -1' (#13573)
parent
c3ec738126
commit
b5e7cef1b1
|
@ -69,6 +69,8 @@ pub fn (mut t Table) free() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const invalid_type_idx = -1
|
||||||
|
|
||||||
pub type FnPanicHandler = fn (&Table, string)
|
pub type FnPanicHandler = fn (&Table, string)
|
||||||
|
|
||||||
fn default_table_panic_handler(t &Table, message 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{
|
pub const invalid_type_symbol = &TypeSymbol{
|
||||||
idx: -1
|
idx: invalid_type_idx
|
||||||
parent_idx: -1
|
parent_idx: invalid_type_idx
|
||||||
language: .v
|
language: .v
|
||||||
mod: 'builtin'
|
mod: 'builtin'
|
||||||
kind: .placeholder
|
kind: .placeholder
|
||||||
|
@ -786,7 +788,7 @@ fn (mut t Table) rewrite_already_registered_symbol(typ TypeSymbol, existing_idx
|
||||||
}
|
}
|
||||||
return existing_idx
|
return existing_idx
|
||||||
}
|
}
|
||||||
return -1
|
return ast.invalid_type_idx
|
||||||
}
|
}
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
|
|
|
@ -697,7 +697,8 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
|
||||||
node.pos)
|
node.pos)
|
||||||
return func.return_type
|
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])
|
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
|
// 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 {
|
&& method.language == .v && method.no_body {
|
||||||
c.error('cannot call a method that does not have a body', node.pos)
|
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])
|
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 }
|
c.check_expected_arg_count(mut node, method) or { return method.return_type }
|
||||||
|
|
|
@ -402,7 +402,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
||||||
receiver_type: rec.typ
|
receiver_type: rec.typ
|
||||||
//
|
//
|
||||||
attrs: p.attrs
|
attrs: p.attrs
|
||||||
is_conditional: conditional_ctdefine_idx != -1
|
is_conditional: conditional_ctdefine_idx != ast.invalid_type_idx
|
||||||
ctdefine_idx: conditional_ctdefine_idx
|
ctdefine_idx: conditional_ctdefine_idx
|
||||||
//
|
//
|
||||||
no_body: no_body
|
no_body: no_body
|
||||||
|
@ -451,7 +451,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
||||||
is_method: false
|
is_method: false
|
||||||
//
|
//
|
||||||
attrs: p.attrs
|
attrs: p.attrs
|
||||||
is_conditional: conditional_ctdefine_idx != -1
|
is_conditional: conditional_ctdefine_idx != ast.invalid_type_idx
|
||||||
ctdefine_idx: conditional_ctdefine_idx
|
ctdefine_idx: conditional_ctdefine_idx
|
||||||
//
|
//
|
||||||
no_body: no_body
|
no_body: no_body
|
||||||
|
@ -506,7 +506,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
||||||
is_markused: is_markused
|
is_markused: is_markused
|
||||||
//
|
//
|
||||||
attrs: p.attrs
|
attrs: p.attrs
|
||||||
is_conditional: conditional_ctdefine_idx != -1
|
is_conditional: conditional_ctdefine_idx != ast.invalid_type_idx
|
||||||
ctdefine_idx: conditional_ctdefine_idx
|
ctdefine_idx: conditional_ctdefine_idx
|
||||||
//
|
//
|
||||||
receiver: ast.StructField{
|
receiver: ast.StructField{
|
||||||
|
|
|
@ -3614,7 +3614,7 @@ fn (mut p Parser) type_decl() ast.TypeDecl {
|
||||||
}
|
}
|
||||||
is_public: is_pub
|
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',
|
p.error_with_pos('cannot register sum type `$name`, another type with this name exists',
|
||||||
name_pos)
|
name_pos)
|
||||||
return ast.SumTypeDecl{}
|
return ast.SumTypeDecl{}
|
||||||
|
@ -3655,7 +3655,7 @@ fn (mut p Parser) type_decl() ast.TypeDecl {
|
||||||
is_public: is_pub
|
is_public: is_pub
|
||||||
})
|
})
|
||||||
type_end_pos := p.prev_tok.pos()
|
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',
|
p.error_with_pos('cannot register alias `$name`, another type with this name exists',
|
||||||
name_pos)
|
name_pos)
|
||||||
return ast.AliasTypeDecl{}
|
return ast.AliasTypeDecl{}
|
||||||
|
|
Loading…
Reference in New Issue