From: Brendan Hansen Date: Mon, 22 Feb 2021 22:15:43 +0000 (-0600) Subject: added anonymous array literals and uncovered bugs X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=a1c2dd1e513f88ed75584e824cad8f9253dc8155;p=onyx.git added anonymous array literals and uncovered bugs --- diff --git a/bin/onyx b/bin/onyx index dce1879a..b9065107 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/include/onyxastnodes.h b/include/onyxastnodes.h index 40150f2c..e36cbf5b 100644 --- a/include/onyxastnodes.h +++ b/include/onyxastnodes.h @@ -218,6 +218,8 @@ typedef enum AstFlags { Ast_Flag_From_Polymorphism = BH_BIT(23), Ast_Flag_Incomplete_Body = BH_BIT(24), + + Ast_Flag_Array_Literal_Typed = BH_BIT(25), } AstFlags; typedef enum UnaryOp { diff --git a/src/onyxastnodes.c b/src/onyxastnodes.c index 98719b8d..606770b4 100644 --- a/src/onyxastnodes.c +++ b/src/onyxastnodes.c @@ -433,6 +433,15 @@ b32 type_check_or_auto_cast(AstTyped** pnode, Type* type) { return 1; } + if (node->kind == Ast_Kind_Array_Literal && node->type_node == NULL) { + i32 value_count = bh_arr_length(((AstArrayLiteral *) node)->values); + node->type = type; // type_make_array(context.ast_alloc, type, value_count); + node->flags |= Ast_Flag_Array_Literal_Typed; + + add_entities_for_node(NULL, (AstNode *) node, NULL, NULL); + return 1; + } + if (node->kind == Ast_Kind_Polymorphic_Proc) { AstFunction* func = polymorphic_proc_lookup((AstPolyProc *) node, PPLM_By_Function_Type, type, node->token); if (func == NULL) return 0; diff --git a/src/onyxchecker.c b/src/onyxchecker.c index f2f1902d..328984c0 100644 --- a/src/onyxchecker.c +++ b/src/onyxchecker.c @@ -1102,17 +1102,24 @@ CheckStatus check_struct_literal(AstStructLiteral* sl) { } CheckStatus check_array_literal(AstArrayLiteral* al) { - if (!node_is_type((AstNode *) al->atnode)) { - onyx_report_error(al->token->pos, "Array type is not a type."); - return Check_Error; - } + if ((al->flags & Ast_Flag_Array_Literal_Typed) == 0) { + if (al->atnode == NULL) return Check_Success; - fill_in_type((AstTyped *) al); + if (!node_is_type((AstNode *) al->atnode)) { + onyx_report_error(al->token->pos, "Array type is not a type."); + return Check_Error; + } - al->type = type_make_array(context.ast_alloc, al->type, bh_arr_length(al->values)); - if (al->type == NULL || al->type->kind != Type_Kind_Array) { - onyx_report_error(al->token->pos, "Expected array type for array literal. This is a compiler bug."); - return Check_Error; + fill_in_type((AstTyped *) al); + if (al->type == NULL) return Check_Error; + + al->type = type_make_array(context.ast_alloc, al->type, bh_arr_length(al->values)); + if (al->type == NULL || al->type->kind != Type_Kind_Array) { + onyx_report_error(al->token->pos, "Expected array type for array literal. This is a compiler bug."); + return Check_Error; + } + + al->flags |= Ast_Flag_Array_Literal_Typed; } if (al->type->Array.count != (u32) bh_arr_length(al->values)) { diff --git a/src/onyxsymres.c b/src/onyxsymres.c index c25168ed..43f7a2db 100644 --- a/src/onyxsymres.c +++ b/src/onyxsymres.c @@ -403,7 +403,7 @@ static SymresStatus symres_array_literal(AstArrayLiteral* al) { SYMRES(type, (AstType **) &al->atnode); al->type_node = (AstType *) al->atnode; - while (al->type_node->kind == Ast_Kind_Type_Alias) + while (al->type_node && al->type_node->kind == Ast_Kind_Type_Alias) al->type_node = ((AstTypeAlias *) al->type_node)->to; bh_arr_each(AstTyped *, expr, al->values)