bugfix with matching function using array literals
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 26 Feb 2023 04:50:29 +0000 (22:50 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 26 Feb 2023 04:50:29 +0000 (22:50 -0600)
compiler/src/astnodes.c

index 1dcfb8434bd0db53a2aa632b3a9289857fcdaa03..b1a5f9841e0e2d3878f778b922b48ced5ce10542 100644 (file)
@@ -595,7 +595,16 @@ TypeMatch unify_node_and_type_(AstTyped** pnode, Type* type, b32 permanent) {
 
         // If this shouldn't make permanent changes and submit entities,
         // just assume that it works and don't submit the entities.
-        if (!permanent) return TYPE_MATCH_SUCCESS;
+        if (!permanent) {
+            //
+            // This only works if the destination type is an array or slice,
+            // otherwise there is no way the array literal would match.
+            if (type->kind != Type_Kind_Array && type->kind != Type_Kind_Slice) {
+                return TYPE_MATCH_FAILED;
+            }
+
+            return TYPE_MATCH_SUCCESS;
+        }
 
         Type* array_type=NULL;
         switch (type->kind) {