minor bug fixes with polymorphic procedures
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 11 Jan 2021 14:39:40 +0000 (08:39 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 11 Jan 2021 14:39:40 +0000 (08:39 -0600)
bin/onyx
onyx.exe
src/onyxchecker.c
src/onyxsymres.c

index 42c02224c1b6319f5943955013b0a329dca35dd6..ebbda14d9289f47517d5a44649c4b1d8718913e5 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index 117b2fcae117a119dfb7a1c4c275b7eeb06ad25e..b6c2e962cef39d3e1e9b1ad30fb5d226b1b584c4 100644 (file)
Binary files a/onyx.exe and b/onyx.exe differ
index 70f29ac417eef4a4fa857d149141a5831a0358e1..4d261ddc83591c4995165fee08cd918333fe01a3 100644 (file)
@@ -45,7 +45,7 @@ CheckStatus check_struct(AstStructType* s_node);
 CheckStatus check_function_header(AstFunction* func);
 CheckStatus check_memres_type(AstMemRes* memres);
 CheckStatus check_memres(AstMemRes* memres);
-CheckStatus check_type_alias(AstTypeAlias* type_alias);
+CheckStatus check_type(AstType* type);
 
 static inline void fill_in_type(AstTyped* node);
 
@@ -1542,6 +1542,8 @@ CheckStatus check_function_header(AstFunction* func) {
             expect_default_param = 1;
         }
 
+        if (local->type_node != NULL) CHECK(type, local->type_node);
+
         fill_in_type((AstTyped *) local);
 
         if (local->type == NULL) {
@@ -1575,6 +1577,8 @@ CheckStatus check_function_header(AstFunction* func) {
         }
     }
 
+    if (func->return_type != NULL) CHECK(type, func->return_type);
+
     func->type = type_build_function_type(semstate.node_allocator, func);
 
     if ((func->flags & Ast_Flag_Exported) != 0) {
@@ -1630,11 +1634,13 @@ CheckStatus check_memres(AstMemRes* memres) {
     return Check_Success;
 }
 
-CheckStatus check_type_alias(AstTypeAlias* type_alias) {
-    AstType* to = type_alias->to;
+CheckStatus check_type(AstType* type) {
+    while (type->kind == Ast_Kind_Type_Alias)
+        type = ((AstTypeAlias *) type)->to;
+
+    if (type->kind == Ast_Kind_Poly_Call_Type) {
+        AstPolyCallType* pc_node = (AstPolyCallType *) type;
 
-    if (to->kind == Ast_Kind_Poly_Call_Type) {
-        AstPolyCallType* pc_node = (AstPolyCallType *) to;
         bh_arr_each(AstNode *, param, pc_node->params) {
             if (!node_is_type(*param)) {
                 CHECK(expression, (AstTyped **) param);
@@ -1693,8 +1699,8 @@ void check_entity(Entity* ent) {
         case Entity_Type_Type_Alias:
             if (ent->type_alias->kind == Ast_Kind_Struct_Type)
                 cs = check_struct((AstStructType *) ent->type_alias);
-            else if (ent->type_alias->kind == Ast_Kind_Type_Alias)
-                check_type_alias((AstTypeAlias *) ent->type_alias);
+            else
+                check_type(ent->type_alias);
             break;
 
         case Entity_Type_Memory_Reservation_Type:
index 9fbf29c689cc538542abc2186e557c0ebdec583a..494c881466bf5ca428cb4e8e6791f72b5e754e92 100644 (file)
@@ -628,31 +628,33 @@ void symres_function_header(AstFunction* func) {
             if (onyx_has_errors()) return;
         }
     }
+    
+    if ((func->flags & Ast_Flag_From_Polymorphism) == 0) {
+        if (func->overloaded_function != NULL) {
+            symres_expression((AstTyped **) &func->overloaded_function);
+            if (func->overloaded_function == NULL) return; // NOTE: Error message will already be generated
 
-    if (func->overloaded_function != NULL) {
-        symres_expression((AstTyped **) &func->overloaded_function);
-        if (func->overloaded_function == NULL) return; // NOTE: Error message will already be generated
-
-        if (func->overloaded_function->kind != Ast_Kind_Overloaded_Function) {
-            onyx_report_error(func->token->pos, "#add_overload directive did not resolve to an overloaded function.");
-            return;
+            if (func->overloaded_function->kind != Ast_Kind_Overloaded_Function) {
+                onyx_report_error(func->token->pos, "#add_overload directive did not resolve to an overloaded function.");
+                return;
 
-        } else {
-            AstOverloadedFunction* ofunc = (AstOverloadedFunction *) func->overloaded_function;
-            bh_arr_push(ofunc->overloads, (AstTyped *) func);
+            } else {
+                AstOverloadedFunction* ofunc = (AstOverloadedFunction *) func->overloaded_function;
+                bh_arr_push(ofunc->overloads, (AstTyped *) func);
+            }
         }
-    }
 
-    if ((func->flags & Ast_Flag_From_Polymorphism) == 0 && func->operator_overload != (BinaryOp) -1) {
-        if (bh_arr_length(func->params) != 2) {
-            onyx_report_error(func->token->pos, "Expected 2 exactly arguments for binary operator overload.");
-        }
+        if (func->operator_overload != (BinaryOp) -1) {
+            if (bh_arr_length(func->params) != 2) {
+                onyx_report_error(func->token->pos, "Expected 2 exactly arguments for binary operator overload.");
+            }
 
-        if (binop_is_assignment(func->operator_overload)) {
-            onyx_report_error(func->token->pos, "'%s' is not currently overloadable.", binaryop_string[func->operator_overload]);
-        }
+            if (binop_is_assignment(func->operator_overload)) {
+                onyx_report_error(func->token->pos, "'%s' is not currently overloadable.", binaryop_string[func->operator_overload]);
+            }
 
-        bh_arr_push(operator_overloads[func->operator_overload], (AstTyped *) func);
+            bh_arr_push(operator_overloads[func->operator_overload], (AstTyped *) func);
+        }
     }
 
     func->return_type = symres_type(func->return_type);