bugfixes with static ifs when types cannot be resolved
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 1 Jun 2021 15:55:35 +0000 (10:55 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 1 Jun 2021 15:55:35 +0000 (10:55 -0500)
bin/onyx
core/builtin.onyx
src/onyxchecker.c

index e4eccdcb078803ccbc87908f29c76b0f263e93cf..b330d5c72f2278e0b622b71d064bd3bce1c7a6e1 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index f252db2528421d479481058b70b0ca97345fa965..25b940e739443907f63f69ad3769e43a71431b5d 100644 (file)
@@ -145,11 +145,21 @@ cfree   :: (ptr: rawptr) do raw_free(context.allocator, ptr);
         // @Robustness: This should be a '#if' when those are added in procedures because
         // otherwise the __initialize intrinsic is going to be generated no matter what.
         // This could be a problem if the type is not something that can be initialized.
+        //
+        // Static ifs in procedures are added now, however, much like nested procedures,
+        // static ifs cannot "see" polymorphic variables. They are only evaluated once
+        // NOT in the context of the polymorphic procedure they are instatiated in.
+        // This will be changed eventually. 'make' can be used for the time being or
+        // for forever.
         use package core.intrinsics.onyx { __initialize }
         if initialize do __initialize(res);
         
         return res;
     }
+
+    make :: ($T: type_expr, allocator := context.allocator) -> ^T {
+        return cast(^T) raw_alloc(allocator, sizeof T);
+    }
 }
 
 
index 333b75b49ebf0a80c4e6d735a62a8cf4a5f29d6f..deafb06270a41e4da4d36483852c31b37f4f6ba8 100644 (file)
@@ -51,6 +51,10 @@ CheckStatus check_memres_type(AstMemRes* memres);
 CheckStatus check_memres(AstMemRes* memres);
 CheckStatus check_type(AstType* type);
 
+
+// HACK HACK HACK
+b32 expression_types_must_be_known = 0;
+
 static inline void fill_in_type(AstTyped* node);
 
 static inline void fill_in_array_count(AstType* type_node) {
@@ -793,8 +797,16 @@ CheckStatus check_binaryop(AstBinaryOp** pbinop, b32 assignment_is_ok) {
 
     if (binop_is_assignment(binop->operation)) return check_binop_assignment(binop, assignment_is_ok);
 
+    if (expression_types_must_be_known) {
+        if (binop->left->type == NULL || binop->right->type == NULL) {
+            onyx_report_error(binop->token->pos, "Internal compiler error: one of the operands types is unknown here.");
+            return Check_Error;
+        }
+    }
+
     // NOTE: Try operator overloading before checking everything else.
-    if (binop->left->type->kind != Type_Kind_Basic || binop->right->type->kind != Type_Kind_Basic) {
+    if ((binop->left->type != NULL && binop->right->type != NULL) &&
+        (binop->left->type->kind != Type_Kind_Basic || binop->right->type->kind != Type_Kind_Basic)) {
         AstCall *implicit_call = binaryop_try_operator_overload(binop);
 
         if (implicit_call != NULL) {
@@ -1790,7 +1802,9 @@ CheckStatus check_type(AstType* type) {
 }
 
 CheckStatus check_static_if(AstIf* static_if) {
+    expression_types_must_be_known = 1;
     CheckStatus result = check_expression(&static_if->cond);
+    expression_types_must_be_known = 0;
 
     if (result > Check_Errors_Start || !(static_if->cond->flags & Ast_Flag_Comptime)) {
         onyx_report_error(static_if->token->pos, "Expected this condition to be compile time known.");