Browse Source

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

gingerBill 6 years ago
parent
commit
94879ed149
4 changed files with 8 additions and 9 deletions
  1. 1 2
      src/check_decl.cpp
  2. 3 4
      src/check_stmt.cpp
  3. 2 1
      src/entity.cpp
  4. 2 2
      src/ir.cpp

+ 1 - 2
src/check_decl.cpp

@@ -1167,11 +1167,10 @@ void check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *decl, Type *ty
 					for_array(i, scope->elements.entries) {
 						Entity *f = scope->elements.entries[i].value;
 						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;
 							if (is_value) uvar->flags |= EntityFlag_Value;
 
-
 							ProcUsingVar puv = {e, uvar};
 							array_add(&using_entities, puv);
 

+ 3 - 4
src/check_stmt.cpp

@@ -496,8 +496,7 @@ bool check_using_stmt_entity(CheckerContext *ctx, AstUsingStmt *us, Ast *expr, b
 			for_array(i, found->elements.entries) {
 				Entity *f = found->elements.entries[i].value;
 				if (f->kind == Entity_Variable) {
-					Entity *uvar = alloc_entity_using_variable(e, f->token, f->type);
-					uvar->using_expr = expr;
+					Entity *uvar = alloc_entity_using_variable(e, f->token, f->type, expr);
 					Entity *prev = scope_insert(ctx->scope, uvar);
 					if (prev != nullptr) {
 						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?
 				}
 
-				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];
 					if (e == nullptr) {
 						continue;
@@ -2071,7 +2070,7 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
 						for_array(i, scope->elements.entries) {
 							Entity *f = scope->elements.entries[i].value;
 							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;
 								Entity *prev = scope_insert(ctx->scope, uvar);
 								if (prev != nullptr) {

+ 2 - 1
src/entity.cpp

@@ -221,12 +221,13 @@ Entity *alloc_entity_variable(Scope *scope, Token token, Type *type, bool is_imm
 	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);
 	token.pos = parent->token.pos;
 	Entity *entity = alloc_entity(Entity_Variable, parent->scope, token, type);
 	entity->using_parent = parent;
 	entity->parent_proc_decl = parent->parent_proc_decl;
+	entity->using_expr = using_expr;
 	entity->flags |= EntityFlag_Using;
 	entity->flags |= EntityFlag_Used;
 	entity->state = EntityState_Resolved;

+ 2 - 2
src/ir.cpp

@@ -9743,7 +9743,7 @@ void ir_begin_procedure_body(irProcedure *proc) {
 				}
 
 				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);
 				}
 
@@ -9766,7 +9766,7 @@ void ir_begin_procedure_body(irProcedure *proc) {
 				if (abi_types.count > 0) {
 					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);
 				}
 				if (is_type_tuple(abi_type)) {