Browse Source

Remove multiple messages for cyclic type errors.

Ginger Bill 8 years ago
parent
commit
88aa74bbb9
2 changed files with 15 additions and 7 deletions
  1. 3 3
      code/demo.odin
  2. 12 4
      src/checker/types.c

+ 3 - 3
code/demo.odin

@@ -1,4 +1,3 @@
-// #import "game.odin";
 #import "fmt.odin";
 
 A :: type struct {
@@ -11,8 +10,9 @@ C :: type struct {
 	a: A;
 };
 
-
 main :: proc() {
-	fmt.println(123);
+	fmt.println(size_of(A));
+	fmt.println(size_of(B));
+	fmt.println(size_of(C));
 }
 

+ 12 - 4
src/checker/types.c

@@ -153,6 +153,7 @@ typedef struct Type {
 	TYPE_KINDS
 #undef TYPE_KIND
 	};
+	bool failure;
 } Type;
 
 // NOTE(bill): Internal sizes of certain types
@@ -1073,10 +1074,11 @@ TypePath *type_path_push(TypePath *tp, Type *t) {
 			// NOTE(bill): This will only print if the path count > 1
 			error(e->token, "\t%.*s", LIT(t->Named.name));
 			tp->failure = true;
+			t->failure = true;
 
 			// NOTE(bill): Just quit immediately
 			// TODO(bill): Try and solve this gracefully
-			gb_exit(1);
+			// gb_exit(1);
 		}
 	}
 
@@ -1113,12 +1115,12 @@ i64 align_formula(i64 size, i64 align) {
 }
 
 i64 type_size_of(BaseTypeSizes s, gbAllocator allocator, Type *t) {
-	i64 align;
+	i64 size;
 	TypePath path = {0};
 	type_path_init(&path);
-	align = type_size_of_internal(s, allocator, t, &path);
+	size = type_size_of_internal(s, allocator, t, &path);
 	type_path_free(&path);
-	return align;
+	return size;
 }
 
 i64 type_align_of(BaseTypeSizes s, gbAllocator allocator, Type *t) {
@@ -1132,6 +1134,9 @@ i64 type_align_of(BaseTypeSizes s, gbAllocator allocator, Type *t) {
 
 
 i64 type_align_of_internal(BaseTypeSizes s, gbAllocator allocator, Type *t, TypePath *path) {
+	if (t->failure) {
+		return FAILURE_ALIGNMENT;
+	}
 	t = base_type(t);
 
 	switch (t->kind) {
@@ -1297,6 +1302,9 @@ bool type_set_offsets(BaseTypeSizes s, gbAllocator allocator, Type *t) {
 }
 
 i64 type_size_of_internal(BaseTypeSizes s, gbAllocator allocator, Type *t, TypePath *path) {
+	if (t->failure) {
+		return FAILURE_SIZE;
+	}
 	t = base_type(t);
 	switch (t->kind) {
 	case Type_Basic: {