Browse Source

Fix `using import` override "bug"

gingerBill 6 years ago
parent
commit
834308d8ce
2 changed files with 18 additions and 1 deletions
  1. 8 0
      core/mem/mem.odin
  2. 10 1
      src/check_decl.cpp

+ 8 - 0
core/mem/mem.odin

@@ -8,6 +8,7 @@ foreign _ {
 swap :: proc[swap16, swap32, swap64];
 
 
+
 set :: proc "contextless" (data: rawptr, value: byte, len: int) -> rawptr {
 	if data == nil do return nil;
 	if len < 0 do return data;
@@ -26,6 +27,13 @@ set :: proc "contextless" (data: rawptr, value: byte, len: int) -> rawptr {
 zero :: proc "contextless" (data: rawptr, len: int) -> rawptr {
 	return set(data, 0, len);
 }
+zero_slice :: proc "contextless" (data: $T/[]$E) {
+	if n := len(data); n > 0 {
+		zero(&data[0], size_of(E)*n);
+	}
+}
+
+
 copy :: proc "contextless" (dst, src: rawptr, len: int) -> rawptr {
 	if src == nil do return dst;
 	// NOTE(bill): This _must_ be implemented like C's memmove

+ 10 - 1
src/check_decl.cpp

@@ -299,7 +299,16 @@ void override_entity_in_scope(Entity *original_entity, Entity *new_entity) {
 	Scope *found_scope = nullptr;
 	Entity *found_entity = nullptr;
 	scope_lookup_parent(original_entity->scope, original_name, &found_scope, &found_entity);
-	GB_ASSERT(found_entity == original_entity);
+
+	// IMPORTANT TODO(bill)
+	// Date: 2018-09-29
+	// This assert fails on `using import` if the name of the alias is the same. What should be the expected behaviour?
+	// Namespace collision or override? Overridding is the current behaviour
+	//
+	//     using import "foo"
+	//     bar :: foo.bar;
+
+	// GB_ASSERT_MSG(found_entity == original_entity, "%.*s == %.*s", LIT(found_entity->token.string), LIT(new_entity->token.string));
 
 	map_set(&found_scope->elements, hash_string(original_name), new_entity);
 }