From: Brendan Hansen Date: Tue, 1 Jun 2021 15:55:35 +0000 (-0500) Subject: bugfixes with static ifs when types cannot be resolved X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=f51c6ad0a58e9b81aab77261019f104a2923424d;p=onyx.git bugfixes with static ifs when types cannot be resolved --- diff --git a/bin/onyx b/bin/onyx index e4eccdcb..b330d5c7 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/core/builtin.onyx b/core/builtin.onyx index f252db25..25b940e7 100644 --- a/core/builtin.onyx +++ b/core/builtin.onyx @@ -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); + } } diff --git a/src/onyxchecker.c b/src/onyxchecker.c index 333b75b4..deafb062 100644 --- a/src/onyxchecker.c +++ b/src/onyxchecker.c @@ -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.");