bugfix with #auto return type being "solved" early
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 15 Oct 2021 18:50:44 +0000 (13:50 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 15 Oct 2021 18:50:44 +0000 (13:50 -0500)
bin/onyx
core/container/iter.onyx
src/checker.c
src/types.c

index 4cea0fe177a853269df8d3abfe4d77ba522ee6ad..c9b126da43d76423dd6beeef760700e9cdde25ff 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index e3593d879d4b4996eefa50bc903824f2aee3805d..6a70f42213198ae677e7636301d1e11712e01772 100644 (file)
@@ -86,8 +86,10 @@ take_one :: (it: Iterator($T)) -> (T, bool) {
 //     ...iterater closed...
 // }
 #operator << macro (dest: Code, it: Iterator($T)) -> bool {
+    take_one :: take_one
+
     cont: bool;
-    (#insert dest), cont = (package core.iter).take_one(it);
+    (#insert dest), cont = take_one(it);
     return !cont;
 }
 
index 8b175999e5c000223e8a58171440fd4dd2a3ed43..08ac5e1912336922385620f85a878fc36af48638 100644 (file)
@@ -1806,7 +1806,10 @@ CheckStatus check_function(AstFunction* func) {
         if (status == Check_Error && func->generated_from && context.cycle_detected == 0)
             ERROR(func->generated_from->pos, "Error in polymorphic procedure generated from this location.");
 
-        if (status != Check_Success) return status;
+        if (status != Check_Success) {
+            expected_return_type = NULL;
+            return status;
+        }
     }
 
     if (*expected_return_type == &type_auto_return) {
index dcb3d041f6879d802d28ffa3b6dfe090e148a366..babbe89ecd364c3a096c95b2930285024ac2f9f8 100644 (file)
@@ -260,21 +260,24 @@ Type* type_build_from_ast(bh_allocator alloc, AstType* type_node) {
             func_type->Function.vararg_arg_pos = -1;
             func_type->Function.return_type = return_type;
 
-            if (param_count > 0)
+            if (param_count > 0) {
                 fori (i, 0, (i64) param_count) {
                     func_type->Function.params[i] = type_build_from_ast(alloc, ftype_node->params[i]);
 
                     // LEAK LEAK LEAK
                     if (func_type->Function.params[i] == NULL) return NULL;
                 }
+            }
 
             char* name = (char *) type_get_unique_name(func_type);
-            if (bh_table_has(u64, type_func_map, name)) {
-                u64 id = bh_table_get(u64, type_func_map, name);
-                Type* existing_type = (Type *) bh_imap_get(&type_map, id);
+            if (func_type->Function.return_type != &type_auto_return) {
+                if (bh_table_has(u64, type_func_map, name)) {
+                    u64 id = bh_table_get(u64, type_func_map, name);
+                    Type* existing_type = (Type *) bh_imap_get(&type_map, id);
 
-                // LEAK LEAK LEAK the func_type that is created
-                return existing_type;
+                    // LEAK LEAK LEAK the func_type that is created
+                    return existing_type;
+                }
             }
 
             type_register(func_type);
@@ -636,12 +639,14 @@ Type* type_build_function_type(bh_allocator alloc, AstFunction* func) {
 
     // CopyPaste from above in type_build_from_ast
     char* name = (char *) type_get_unique_name(func_type);
-    if (bh_table_has(u64, type_func_map, name)) {
-        u64 id = bh_table_get(u64, type_func_map, name);
-        Type* existing_type = (Type *) bh_imap_get(&type_map, id);
+    if (func_type->Function.return_type != &type_auto_return) {
+        if (bh_table_has(u64, type_func_map, name)) {
+            u64 id = bh_table_get(u64, type_func_map, name);
+            Type* existing_type = (Type *) bh_imap_get(&type_map, id);
 
-        // LEAK LEAK LEAK the func_type that is created
-        return existing_type;
+            // LEAK LEAK LEAK the func_type that is created
+            return existing_type;
+        }
     }
 
     type_register(func_type);