From: Brendan Hansen Date: Fri, 15 Oct 2021 18:50:44 +0000 (-0500) Subject: bugfix with #auto return type being "solved" early X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=88834768c808be9fae4f46b4c909d0e3b68fdb3a;p=onyx.git bugfix with #auto return type being "solved" early --- diff --git a/bin/onyx b/bin/onyx index 4cea0fe1..c9b126da 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/core/container/iter.onyx b/core/container/iter.onyx index e3593d87..6a70f422 100644 --- a/core/container/iter.onyx +++ b/core/container/iter.onyx @@ -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; } diff --git a/src/checker.c b/src/checker.c index 8b175999..08ac5e19 100644 --- a/src/checker.c +++ b/src/checker.c @@ -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) { diff --git a/src/types.c b/src/types.c index dcb3d041..babbe89e 100644 --- a/src/types.c +++ b/src/types.c @@ -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);