diff options
| author | Ginger Bill <bill@gingerbill.org> | 2017-07-10 20:39:42 +0100 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2017-07-10 20:39:42 +0100 |
| commit | ce4b7b8b7d54e889413cf2d43d85f2e4f4a0b007 (patch) | |
| tree | e0e6335ddb211cdb927e73c7814d2b375124f7fe /src/check_stmt.cpp | |
| parent | 069a47220e55d0b64732c0eb146802edb6388246 (diff) | |
Nested record declarations
Diffstat (limited to 'src/check_stmt.cpp')
| -rw-r--r-- | src/check_stmt.cpp | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index fe70fd672..c7aa5424f 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -473,7 +473,39 @@ bool check_using_stmt_entity(Checker *c, AstNodeUsingStmt *us, AstNode *expr, bo switch (e->kind) { case Entity_TypeName: { Type *t = base_type(e->type); - if (is_type_union(t)) { + if (t->kind == Type_Record) { + Scope *s = t->Record.scope; + if (s != nullptr) { + for_array(i, s->elements.entries) { + Entity *f = s->elements.entries[i].value; + if (f->kind != Entity_Variable) { + Entity *found = scope_insert_entity(c->context.scope, f); + if (found != nullptr) { + gbString expr_str = expr_to_string(expr); + error(us->token, "Namespace collision while `using` `%s` of: %.*s", expr_str, LIT(found->token.string)); + gb_string_free(expr_str); + return false; + } + f->using_parent = e; + } + } + } else if (is_type_enum(t)) { + for (isize i = 0; i < t->Record.field_count; i++) { + Entity *f = t->Record.fields[i]; + Entity *found = scope_insert_entity(c->context.scope, f); + if (found != nullptr) { + gbString expr_str = expr_to_string(expr); + error(us->token, "Namespace collision while `using` `%s` of: %.*s", expr_str, LIT(found->token.string)); + gb_string_free(expr_str); + return false; + } + f->using_parent = e; + } + } + } else { + error(us->token, "`using` can be only applied to record type entities"); + } + /* if (is_type_union(t)) { TokenPos pos = ast_node_token(expr).pos; for (isize i = 1; i < t->Record.variant_count; i++) { Entity *f = t->Record.variants[i]; @@ -502,7 +534,7 @@ bool check_using_stmt_entity(Checker *c, AstNodeUsingStmt *us, AstNode *expr, bo } else { error(us->token, "`using` can be only applied to `union` or `enum` type entities"); - } + } */ } break; case Entity_ImportName: { |