better array literals with polymorphism
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 13 Oct 2021 16:32:27 +0000 (11:32 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 13 Oct 2021 16:32:27 +0000 (11:32 -0500)
bin/onyx
src/astnodes.c

index 30fc0b3b28b6beee1169e288241533b2805c6392..8c51fa8886d2d0a41a4b5defe0565bfa1feecf03 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index a99d18d9aa19b18ecb344914f5554a1327f7958c..c10b89762a057ca09b2f7bb8f74278f17b0e601d 100644 (file)
@@ -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;
         }
     }