From: Brendan Hansen Date: Wed, 2 Jun 2021 23:53:12 +0000 (-0500) Subject: better handling for infinite loop prevention with overloads X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=00909d4ade21b13d360bb90bbd59909a86b84249;p=onyx.git better handling for infinite loop prevention with overloads --- diff --git a/bin/onyx b/bin/onyx index d2adfee3..5369eee0 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/include/onyxutils.h b/include/onyxutils.h index b9c9b219..0dc7f8bc 100644 --- a/include/onyxutils.h +++ b/include/onyxutils.h @@ -26,6 +26,8 @@ AstNode* symbol_resolve(Scope* start_scope, OnyxToken* tkn); AstNode* try_symbol_raw_resolve_from_node(AstNode* node, char* symbol); AstNode* try_symbol_resolve_from_node(AstNode* node, OnyxToken* token); +void build_all_overload_options(bh_arr(AstTyped *) overloads, bh_imap* all_overloads); + u32 char_to_base16_value(char x); // Returns the length after processing the string. diff --git a/src/onyxchecker.c b/src/onyxchecker.c index 28f15d85..041cace8 100644 --- a/src/onyxchecker.c +++ b/src/onyxchecker.c @@ -1062,7 +1062,9 @@ CheckStatus check_struct_literal(AstStructLiteral* sl) { CHECK(expression, actual); // HACK HACK HACK - if ((*actual)->type == NULL && (*actual)->kind == Ast_Kind_Function) { + if ((*actual)->type == NULL && + (*actual)->entity != NULL && + (*actual)->entity->state <= Entity_State_Check_Types) { return Check_Yield_Macro; } @@ -1618,23 +1620,30 @@ CheckStatus check_function(AstFunction* func) { CheckStatus check_overloaded_function(AstOverloadedFunction* func) { b32 done = 1; - bh_arr_each(AstTyped *, node, func->overloads) { - if ( (*node)->kind != Ast_Kind_Function - && (*node)->kind != Ast_Kind_Polymorphic_Proc - && (*node)->kind != Ast_Kind_Overloaded_Function) { - onyx_report_error((*node)->token->pos, "Overload option not procedure. Got '%s'", - onyx_ast_node_kind_string((*node)->kind)); + bh_imap all_overloads; + bh_imap_init(&all_overloads, global_heap_allocator, 4); + build_all_overload_options(func->overloads, &all_overloads); + bh_arr_each(bh__imap_entry, entry, all_overloads.entries) { + AstTyped* node = (AstTyped *) entry->key; + if (node->kind == Ast_Kind_Overloaded_Function) continue; + + if ( node->kind != Ast_Kind_Function + && node->kind != Ast_Kind_Polymorphic_Proc) { + onyx_report_error(node->token->pos, "Overload option not procedure. Got '%s'", + onyx_ast_node_kind_string(node->kind)); + + bh_imap_free(&all_overloads); return Check_Error; } - if ((*node)->entity && - (*node)->entity->type != Entity_Type_Overloaded_Function && - (*node)->entity->state <= Entity_State_Check_Types) { + if (node->entity && node->entity->state <= Entity_State_Check_Types) { done = 0; } } + bh_imap_free(&all_overloads); + if (done) return Check_Success; else return Check_Yield_Macro; } diff --git a/src/onyxutils.c b/src/onyxutils.c index 18bdc5aa..6717d882 100644 --- a/src/onyxutils.c +++ b/src/onyxutils.c @@ -974,7 +974,7 @@ AstFunction* polymorphic_proc_build_only_header(AstPolyProc* pp, PolyProcLookupM // an "entries" array that, so long as nothing is ever removed from it, will maintain the order in // which entries were put into the map. This is useful because a simple recursive algorithm can // collect all the overloads into the map, and also use the map to provide a base case. -static void build_all_overload_options(bh_arr(AstTyped *) overloads, bh_imap* all_overloads) { +void build_all_overload_options(bh_arr(AstTyped *) overloads, bh_imap* all_overloads) { bh_arr_each(AstTyped *, node, overloads) { if (bh_imap_has(all_overloads, (u64) *node)) continue;