From: Brendan Hansen Date: Mon, 11 Jan 2021 14:39:40 +0000 (-0600) Subject: minor bug fixes with polymorphic procedures X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=034ff02311e86d2d4d87c0624096ca77e4dc07fc;p=onyx.git minor bug fixes with polymorphic procedures --- diff --git a/bin/onyx b/bin/onyx index 42c02224..ebbda14d 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/onyx.exe b/onyx.exe index 117b2fca..b6c2e962 100644 Binary files a/onyx.exe and b/onyx.exe differ diff --git a/src/onyxchecker.c b/src/onyxchecker.c index 70f29ac4..4d261ddc 100644 --- a/src/onyxchecker.c +++ b/src/onyxchecker.c @@ -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: diff --git a/src/onyxsymres.c b/src/onyxsymres.c index 9fbf29c6..494c8814 100644 --- a/src/onyxsymres.c +++ b/src/onyxsymres.c @@ -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);