gingerBill 5 years ago
parent
commit
e86fde3cb1
3 changed files with 23 additions and 2 deletions
  1. 10 0
      src/array.cpp
  2. 5 1
      src/check_decl.cpp
  3. 8 1
      src/check_expr.cpp

+ 10 - 0
src/array.cpp

@@ -41,6 +41,7 @@ template <typename T> void     array_reserve       (Array<T> *array, isize capac
 template <typename T> void     array_resize        (Array<T> *array, isize count);
 template <typename T> void     array_resize        (Array<T> *array, isize count);
 template <typename T> void     array_set_capacity  (Array<T> *array, isize capacity);
 template <typename T> void     array_set_capacity  (Array<T> *array, isize capacity);
 template <typename T> Array<T> array_slice         (Array<T> const &array, isize lo, isize hi);
 template <typename T> Array<T> array_slice         (Array<T> const &array, isize lo, isize hi);
+template <typename T> Array<T> array_clone         (gbAllocator const &a, Array<T> const &array);
 
 
 
 
 
 
@@ -243,6 +244,15 @@ gb_inline Array<T> array_slice(Array<T> const &array, isize lo, isize hi) {
 	}
 	}
 	return out;
 	return out;
 }
 }
+
+template <typename T>
+Array<T> array_clone(gbAllocator const &allocator, Array<T> const &array) {
+	auto clone = array_make<T>(allocator, array.count, array.count);
+	array_copy(&clone, array, 0);
+	return clone;
+}
+
+
 template <typename T>
 template <typename T>
 void array_ordered_remove(Array<T> *array, isize index) {
 void array_ordered_remove(Array<T> *array, isize index) {
 	GB_ASSERT(0 <= index && index < array->count);
 	GB_ASSERT(0 <= index && index < array->count);

+ 5 - 1
src/check_decl.cpp

@@ -435,7 +435,11 @@ void check_const_decl(CheckerContext *ctx, Entity *e, Ast *type_expr, Ast *init,
 		case Addressing_ProcGroup:
 		case Addressing_ProcGroup:
 			GB_ASSERT(operand.proc_group != nullptr);
 			GB_ASSERT(operand.proc_group != nullptr);
 			GB_ASSERT(operand.proc_group->kind == Entity_ProcGroup);
 			GB_ASSERT(operand.proc_group->kind == Entity_ProcGroup);
-			override_entity_in_scope(e, operand.proc_group);
+			// NOTE(bill, 2020-06-10): It is better to just clone the contents than overriding the entity in the scope
+			// Thank goodness I made entities a tagged union to allow for this implace patching
+			// override_entity_in_scope(e, operand.proc_group);
+			e->kind = Entity_ProcGroup;
+			e->ProcGroup.entities = array_clone(heap_allocator(), operand.proc_group->ProcGroup.entities);
 			return;
 			return;
 		}
 		}
 
 

+ 8 - 1
src/check_expr.cpp

@@ -3492,7 +3492,14 @@ Entity *check_selector(CheckerContext *c, Operand *operand, Ast *node, Type *typ
 			}
 			}
 
 
 			check_entity_decl(c, entity, nullptr, nullptr);
 			check_entity_decl(c, entity, nullptr, nullptr);
-			GB_ASSERT(entity->type != nullptr);
+			if (entity->kind == Entity_ProcGroup) {
+				operand->mode = Addressing_ProcGroup;
+				operand->proc_group = entity;
+
+				add_type_and_value(c->info, operand->expr, operand->mode, operand->type, operand->value);
+				return entity;
+			}
+			GB_ASSERT_MSG(entity->type != nullptr, "%.*s (%.*s)", LIT(entity->token.string), LIT(entity_strings[entity->kind]));
 
 
 			if (!is_entity_exported(entity, allow_builtin)) {
 			if (!is_entity_exported(entity, allow_builtin)) {
 				gbString sel_str = expr_to_string(selector);
 				gbString sel_str = expr_to_string(selector);