Browse Source

Add error message for when trying to assign a type to a variable.

gingerBill 6 năm trước cách đây
mục cha
commit
886054f0f8
2 tập tin đã thay đổi với 10 bổ sung3 xóa
  1. 2 3
      core/c/c.odin
  2. 8 0
      src/check_decl.cpp

+ 2 - 3
core/c/c.odin

@@ -1,7 +1,6 @@
 package c
 
 import b "core:builtin"
-import "core:os"
 
 CHAR_BIT :: 8;
 
@@ -15,8 +14,8 @@ ushort :: b.u16;
 int    :: b.i32;
 uint   :: b.u32;
 
-long  :: (os.OS == "windows" || size_of(b.rawptr) == 4) ? b.i32 : b.i64;
-ulong :: (os.OS == "windows" || size_of(b.rawptr) == 4) ? b.u32 : b.u64;
+long  :: (ODIN_OS == "windows" || size_of(b.rawptr) == 4) ? b.i32 : b.i64;
+ulong :: (ODIN_OS == "windows" || size_of(b.rawptr) == 4) ? b.u32 : b.u64;
 
 longlong       :: b.i64;
 ulonglong      :: b.u64;

+ 8 - 0
src/check_decl.cpp

@@ -40,6 +40,14 @@ Type *check_init_variable(CheckerContext *ctx, Entity *e, Operand *operand, Stri
 		return nullptr;
 	}
 
+	if (operand->mode == Addressing_Type) {
+		gbString t = type_to_string(operand->type);
+		error(operand->expr, "Cannot assign a type '%s' to variable '%.*s'", t, LIT(e->token.string));
+		gb_string_free(t);
+		e->type = operand->type;
+		return nullptr;
+	}
+
 
 
 	if (e->type == nullptr) {