diff options
| author | gingerBill <bill@gingerbill.org> | 2018-03-23 15:23:14 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2018-03-23 15:23:14 +0000 |
| commit | 5bf0f9d630f16287f7977bbec1d85af9bcb432cf (patch) | |
| tree | a895fb66bc86417e3f70578cbe45218ac265464a /src/check_decl.cpp | |
| parent | fff4ead96ab7cab8091f990e6a947a08a23fd3a4 (diff) | |
Fix type cycle bug
Diffstat (limited to 'src/check_decl.cpp')
| -rw-r--r-- | src/check_decl.cpp | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/check_decl.cpp b/src/check_decl.cpp index 1215e337d..52133bf32 100644 --- a/src/check_decl.cpp +++ b/src/check_decl.cpp @@ -864,13 +864,21 @@ void check_proc_group_decl(Checker *c, Entity *pg_entity, DeclInfo *d) { } void check_entity_decl(Checker *c, Entity *e, DeclInfo *d, Type *named_type) { - if (e->type != nullptr) { + if (e->state == EntityState_Resolved) { + return; + } + String name = e->token.string; + + if (e->type != nullptr || e->state != EntityState_Unresolved) { + error(e->token, "Illegal declaration cycle of `%.*s`", LIT(name)); return; } + GB_ASSERT(e->state == EntityState_Unresolved); + #if 0 char buf[256] = {}; - isize n = gb_snprintf(buf, 256, "%.*s %d", LIT(e->token.string), e->kind); + isize n = gb_snprintf(buf, 256, "%.*s %d", LIT(name), e->kind); Timings timings = {}; timings_init(&timings, make_string(cast(u8 *)buf, n-1), 16); defer ({ @@ -887,17 +895,21 @@ void check_entity_decl(Checker *c, Entity *e, DeclInfo *d, Type *named_type) { if (d == nullptr) { // TODO(bill): Err here? e->type = t_invalid; + e->state = EntityState_Resolved; set_base_type(named_type, t_invalid); return; - // GB_PANIC("'%.*s' should been declared!", LIT(e->token.string)); + // GB_PANIC("'%.*s' should been declared!", LIT(name)); } } CheckerContext prev = c->context; c->context.scope = d->scope; c->context.decl = d; + c->context.type_level = 0; e->parent_proc_decl = c->context.curr_proc_decl; + e->state = EntityState_InProgress; + switch (e->kind) { case Entity_Variable: @@ -918,6 +930,8 @@ void check_entity_decl(Checker *c, Entity *e, DeclInfo *d, Type *named_type) { break; } + e->state = EntityState_Resolved; + c->context = prev; #undef TIME_SECTION |