distinct type bug fixes
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 25 Nov 2021 04:43:58 +0000 (22:43 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 25 Nov 2021 04:43:58 +0000 (22:43 -0600)
src/astnodes.c
src/types.c

index 55d6b13fab22288760af3b99e39e8b4ea3323cbb..8990c47f398b6636fd7585ec1ef4fece90830841 100644 (file)
@@ -403,6 +403,7 @@ b32 convert_numlit_to_type(AstNumLit* num, Type* to_type) {
 
     Type *type = to_type;
     if (type->kind == Type_Kind_Enum) type = type->Enum.backing;
+    if (type->kind == Type_Kind_Distinct) type = type->Distinct.base_type;
 
     if (num->type->Basic.kind == Basic_Kind_Int_Unsized) {
 
index 9ffdfaf68892e4438eda4c1116b36714846c2e09..e9b8ec60f73515fda140f6eb0aeef892c70c24d2 100644 (file)
@@ -1221,6 +1221,7 @@ b32 type_is_bool(Type* type) {
 b32 type_is_small_integer(Type* type) {
     if (type == NULL) return 0;
     if (type->kind == Type_Kind_Enum) return type_is_small_integer(type->Enum.backing);
+    if (type->kind == Type_Kind_Distinct) return type_is_small_integer(type->Distinct.base_type);
     if (type->kind != Type_Kind_Basic) return 0;
 
     return type->Basic.kind >= Basic_Kind_I8 && type->Basic.kind <= Basic_Kind_U32;
@@ -1229,6 +1230,7 @@ b32 type_is_small_integer(Type* type) {
 b32 type_is_integer(Type* type) {
     if (type == NULL) return 0;
     if (type->kind == Type_Kind_Enum) return type_is_integer(type->Enum.backing);
+    if (type->kind == Type_Kind_Distinct) return type_is_integer(type->Distinct.base_type);
     if (type->kind != Type_Kind_Basic) return 0;
 
     return (type->Basic.kind >= Basic_Kind_I8 && type->Basic.kind <= Basic_Kind_U64)
@@ -1238,6 +1240,7 @@ b32 type_is_integer(Type* type) {
 b32 type_is_numeric(Type* type) {
     if (type == NULL) return 0;
     if (type->kind == Type_Kind_Enum) return 1;
+    if (type->kind == Type_Kind_Distinct) return type_is_numeric(type->Distinct.base_type);
     if (type->kind != Type_Kind_Basic) return 0;
 
     return type->Basic.kind >= Basic_Kind_Int_Unsized && type->Basic.kind <= Basic_Kind_F64;
@@ -1249,7 +1252,8 @@ b32 type_is_compound(Type* type) {
         && type->kind != Type_Kind_Pointer
         && type->kind != Type_Kind_Enum
         && type->kind != Type_Kind_Function
-        && type->kind != Type_Kind_Array;
+        && type->kind != Type_Kind_Array
+        && type->kind != Type_Kind_Distinct;
 }
 
 b32 type_is_simd(Type* type) {