From 615fa82d1f5ff44ce4e654be41c0a99ddef29fb3 Mon Sep 17 00:00:00 2001 From: Ginger Bill Date: Sat, 6 May 2017 20:55:09 +0100 Subject: [PATCH] Fix `using` issue #62 --- src/check_stmt.c | 17 ++++++++++------- src/ir.c | 1 + 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/check_stmt.c b/src/check_stmt.c index fc898ec62..99e972727 100644 --- a/src/check_stmt.c +++ b/src/check_stmt.c @@ -439,6 +439,8 @@ bool check_using_stmt_entity(Checker *c, AstNodeUsingStmt *us, AstNode *expr, bo return true; } + add_entity_use(c, expr, e); + switch (e->kind) { case Entity_Alias: { if (e->Alias.original != NULL) { @@ -506,17 +508,18 @@ bool check_using_stmt_entity(Checker *c, AstNodeUsingStmt *us, AstNode *expr, bo case Entity_Variable: { Type *t = base_type(type_deref(e->type)); - if (is_type_struct(t) || is_type_raw_union(t)) { + if (is_type_struct(t) || is_type_raw_union(t) || is_type_union(t)) { // TODO(bill): Make it work for unions too - Scope **found = map_scope_get(&c->info.scopes, hash_pointer(t->Record.node)); - GB_ASSERT(found != NULL); - for_array(i, (*found)->elements.entries) { - Entity *f = (*found)->elements.entries.e[i].value; + Scope **found_ = map_scope_get(&c->info.scopes, hash_pointer(t->Record.node)); + GB_ASSERT(found_ != NULL); + Scope *found = *found_; + for_array(i, found->elements.entries) { + Entity *f = found->elements.entries.e[i].value; if (f->kind == Entity_Variable) { Entity *uvar = make_entity_using_variable(c->allocator, e, f->token, f->type); - if (is_selector) { + // if (is_selector) { uvar->using_expr = expr; - } + // } Entity *prev = scope_insert_entity(c->context.scope, uvar); if (prev != NULL) { gbString expr_str = expr_to_string(expr); diff --git a/src/ir.c b/src/ir.c index bb9d8b7e8..0caf597bc 100644 --- a/src/ir.c +++ b/src/ir.c @@ -4696,6 +4696,7 @@ irValue *ir_get_using_variable(irProcedure *proc, Entity *e) { if (pv != NULL) { v = *pv; } else { + GB_ASSERT_MSG(e->using_expr != NULL, "%.*s", LIT(name)); v = ir_build_addr(proc, e->using_expr).addr; } GB_ASSERT(v != NULL);