Fix Compiler assertion when applying using to _ procedure parameter. #451

This commit is contained in:
gingerBill
2019-10-26 12:14:04 +01:00
parent 2c75fe2314
commit 94879ed149
4 changed files with 8 additions and 9 deletions
+1 -2
View File
@@ -1167,11 +1167,10 @@ void check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *decl, Type *ty
for_array(i, scope->elements.entries) { for_array(i, scope->elements.entries) {
Entity *f = scope->elements.entries[i].value; Entity *f = scope->elements.entries[i].value;
if (f->kind == Entity_Variable) { if (f->kind == Entity_Variable) {
Entity *uvar = alloc_entity_using_variable(e, f->token, f->type); Entity *uvar = alloc_entity_using_variable(e, f->token, f->type, nullptr);
uvar->Variable.is_immutable = is_immutable; uvar->Variable.is_immutable = is_immutable;
if (is_value) uvar->flags |= EntityFlag_Value; if (is_value) uvar->flags |= EntityFlag_Value;
ProcUsingVar puv = {e, uvar}; ProcUsingVar puv = {e, uvar};
array_add(&using_entities, puv); array_add(&using_entities, puv);
+3 -4
View File
@@ -496,8 +496,7 @@ bool check_using_stmt_entity(CheckerContext *ctx, AstUsingStmt *us, Ast *expr, b
for_array(i, found->elements.entries) { for_array(i, found->elements.entries) {
Entity *f = found->elements.entries[i].value; Entity *f = found->elements.entries[i].value;
if (f->kind == Entity_Variable) { if (f->kind == Entity_Variable) {
Entity *uvar = alloc_entity_using_variable(e, f->token, f->type); Entity *uvar = alloc_entity_using_variable(e, f->token, f->type, expr);
uvar->using_expr = expr;
Entity *prev = scope_insert(ctx->scope, uvar); Entity *prev = scope_insert(ctx->scope, uvar);
if (prev != nullptr) { if (prev != nullptr) {
gbString expr_str = expr_to_string(expr); gbString expr_str = expr_to_string(expr);
@@ -2052,7 +2051,7 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
// TODO(bill): Should a 'continue' happen here? // TODO(bill): Should a 'continue' happen here?
} }
for (isize entity_index = 0; entity_index < entity_count; entity_index++) { for (isize entity_index = 0; entity_index < 1; entity_index++) {
Entity *e = entities[entity_index]; Entity *e = entities[entity_index];
if (e == nullptr) { if (e == nullptr) {
continue; continue;
@@ -2071,7 +2070,7 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
for_array(i, scope->elements.entries) { for_array(i, scope->elements.entries) {
Entity *f = scope->elements.entries[i].value; Entity *f = scope->elements.entries[i].value;
if (f->kind == Entity_Variable) { if (f->kind == Entity_Variable) {
Entity *uvar = alloc_entity_using_variable(e, f->token, f->type); Entity *uvar = alloc_entity_using_variable(e, f->token, f->type, nullptr);
uvar->Variable.is_immutable = is_immutable; uvar->Variable.is_immutable = is_immutable;
Entity *prev = scope_insert(ctx->scope, uvar); Entity *prev = scope_insert(ctx->scope, uvar);
if (prev != nullptr) { if (prev != nullptr) {
+2 -1
View File
@@ -221,12 +221,13 @@ Entity *alloc_entity_variable(Scope *scope, Token token, Type *type, bool is_imm
return entity; return entity;
} }
Entity *alloc_entity_using_variable(Entity *parent, Token token, Type *type) { Entity *alloc_entity_using_variable(Entity *parent, Token token, Type *type, Ast *using_expr) {
GB_ASSERT(parent != nullptr); GB_ASSERT(parent != nullptr);
token.pos = parent->token.pos; token.pos = parent->token.pos;
Entity *entity = alloc_entity(Entity_Variable, parent->scope, token, type); Entity *entity = alloc_entity(Entity_Variable, parent->scope, token, type);
entity->using_parent = parent; entity->using_parent = parent;
entity->parent_proc_decl = parent->parent_proc_decl; entity->parent_proc_decl = parent->parent_proc_decl;
entity->using_expr = using_expr;
entity->flags |= EntityFlag_Using; entity->flags |= EntityFlag_Using;
entity->flags |= EntityFlag_Used; entity->flags |= EntityFlag_Used;
entity->state = EntityState_Resolved; entity->state = EntityState_Resolved;
+2 -2
View File
@@ -9743,7 +9743,7 @@ void ir_begin_procedure_body(irProcedure *proc) {
} }
Type *abi_type = proc->type->Proc.abi_compat_params[i]; Type *abi_type = proc->type->Proc.abi_compat_params[i];
if (e->token.string != "" && !is_blank_ident(e->token)) { if (e->token.string != "") {
ir_add_param(proc, e, name, abi_type, parameter_index); ir_add_param(proc, e, name, abi_type, parameter_index);
} }
@@ -9766,7 +9766,7 @@ void ir_begin_procedure_body(irProcedure *proc) {
if (abi_types.count > 0) { if (abi_types.count > 0) {
abi_type = abi_types[i]; abi_type = abi_types[i];
} }
if (e->token.string != "" && !is_blank_ident(e->token)) { if (e->token.string != "") {
ir_add_param(proc, e, nullptr, abi_type, parameter_index); ir_add_param(proc, e, nullptr, abi_type, parameter_index);
} }
if (is_type_tuple(abi_type)) { if (is_type_tuple(abi_type)) {