Fix illegal type declaration error

This commit is contained in:
Ginger Bill
2016-11-30 20:07:23 +00:00
parent b76c8abe73
commit ab2ca7cf59
6 changed files with 46 additions and 33 deletions
+20 -19
View File
@@ -724,7 +724,7 @@ bool add_entity(Checker *c, Scope *scope, AstNode *identifier, Entity *entity) {
return false;
} else {
TokenPos pos = insert_entity->token.pos;
if (token_pos_are_equal(pos, entity->token.pos)) {
if (token_pos_eq(pos, entity->token.pos)) {
// NOTE(bill): Error should have been handled already
return false;
}
@@ -1048,27 +1048,29 @@ void check_global_entities_by_kind(Checker *c, EntityKind kind) {
for_array(i, c->info.entities.entries) {
MapDeclInfoEntry *entry = &c->info.entities.entries.e[i];
Entity *e = cast(Entity *)cast(uintptr)entry->key.key;
if (e->kind == kind) {
DeclInfo *d = entry->value;
if (d->scope != e->scope) {
continue;
}
DeclInfo *d = entry->value;
add_curr_ast_file(c, d->scope->file);
if (kind != Entity_Procedure && str_eq(e->token.string, str_lit("main"))) {
if (e->scope->is_init) {
error(e->token, "`main` is reserved as the entry point procedure in the initial scope");
continue;
}
} else if (e->scope->is_global && str_eq(e->token.string, str_lit("main"))) {
if (e->kind != kind) {
continue;
}
if (d->scope != e->scope) {
continue;
}
add_curr_ast_file(c, d->scope->file);
if (e->kind != Entity_Procedure && str_eq(e->token.string, str_lit("main"))) {
if (e->scope->is_init) {
error(e->token, "`main` is reserved as the entry point procedure in the initial scope");
continue;
}
Scope *prev_scope = c->context.scope;
c->context.scope = d->scope;
check_entity_decl(c, e, d, NULL, NULL);
} else if (e->scope->is_global && str_eq(e->token.string, str_lit("main"))) {
error(e->token, "`main` is reserved as the entry point procedure in the initial scope");
continue;
}
Scope *prev_scope = c->context.scope;
c->context.scope = d->scope;
check_entity_decl(c, e, d, NULL, NULL);
}
}
@@ -1383,14 +1385,13 @@ void check_parsed_files(Checker *c) {
}
check_global_entities_by_kind(c, Entity_TypeName);
init_preload_types(c);
add_implicit_value(c, ImplicitValue_context, str_lit("context"), str_lit("__context"), t_context);
check_global_entities_by_kind(c, Entity_Constant);
check_global_entities_by_kind(c, Entity_Procedure);
check_global_entities_by_kind(c, Entity_Variable);
for (isize i = 1; i < ImplicitValue_Count; i++) {
// NOTE(bill): First is invalid
Entity *e = c->info.implicit_values[i];
+1 -1
View File
@@ -305,7 +305,7 @@ void check_type_decl(Checker *c, Entity *e, AstNode *type_expr, Type *def, Cycle
named->Named.base = bt;
named->Named.base = base_type(named->Named.base);
if (named->Named.base == t_invalid) {
gb_printf("check_type_decl: %s\n", type_to_string(named));
// gb_printf("check_type_decl: %s\n", type_to_string(named));
}
cycle_checker_destroy(&local_cycle_checker);
+9 -3
View File
@@ -1329,14 +1329,19 @@ end:
if (is_type_named(type)) {
if (type->Named.base == NULL) {
error_node(e, "Invalid type definition");
type->Named.base = t_invalid;
}
}
if (is_type_typed(type)) {
add_type_and_value(&c->info, e, Addressing_Type, type, null_value);
} else {
error_node(e, "Invalid type definition");
type = t_invalid;
}
set_base_type(named_type, type);
GB_ASSERT(is_type_typed(type));
add_type_and_value(&c->info, e, Addressing_Type, type, null_value);
return type;
@@ -3755,7 +3760,8 @@ ExprKind check_call_expr(Checker *c, Operand *operand, AstNode *call) {
}
Type *proc_type = base_type(operand->type);
if (proc_type == NULL || proc_type->kind != Type_Proc) {
if (proc_type == NULL || proc_type->kind != Type_Proc ||
!(operand->mode == Addressing_Value || operand->mode == Addressing_Variable)) {
AstNode *e = operand->expr;
gbString str = expr_to_string(e);
error_node(e, "Cannot call a non-procedure: `%s`", str);
+3
View File
@@ -490,6 +490,9 @@ bool is_type_string(Type *t) {
}
bool is_type_typed(Type *t) {
t = base_type(t);
if (t == NULL) {
return false;
}
if (t->kind == Type_Basic) {
return (t->Basic.flags & BasicFlag_Untyped) == 0;
}