From: Brendan Hansen Date: Wed, 13 Oct 2021 16:32:27 +0000 (-0500) Subject: better array literals with polymorphism X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=e108b3d79c3e2159682b3ee95b807a45035aa389;p=onyx.git better array literals with polymorphism --- diff --git a/bin/onyx b/bin/onyx index 30fc0b3b..8c51fa88 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/src/astnodes.c b/src/astnodes.c index a99d18d9..c10b8976 100644 --- a/src/astnodes.c +++ b/src/astnodes.c @@ -528,7 +528,7 @@ b32 unify_node_and_type_(AstTyped** pnode, Type* type, b32 permanent) { return 1; } - if (node->kind == Ast_Kind_Array_Literal && node->type_node == NULL) { + if (node->kind == Ast_Kind_Array_Literal && node->type == NULL) { if (node->entity != NULL) return 1; // If this shouldn't make permanent changes and submit entities, @@ -639,10 +639,12 @@ b32 unify_node_and_type_(AstTyped** pnode, Type* type, b32 permanent) { else if (node_type && type->kind == Type_Kind_Slice) { if (node_type->kind == Type_Kind_Array || node_type->kind == Type_Kind_DynArray || node_type->kind == Type_Kind_VarArgs) { char* dummy; - if (cast_is_legal(node_type, type, &dummy)) { + b32 legal = cast_is_legal(node_type, type, &dummy); + if (permanent && legal) { *pnode = (AstTyped *) make_cast(context.ast_alloc, node, type); - return 1; } + + return legal; } }