From c846156842a87f6ca8c9b88229fb76b8457374f9 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Thu, 5 May 2022 22:11:37 -0500 Subject: [PATCH] printing out all overloads when #match fails --- include/astnodes.h | 2 +- src/checker.c | 2 +- src/utils.c | 16 +++++++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/include/astnodes.h b/include/astnodes.h index 644acd6d..b209ce0e 100644 --- a/include/astnodes.h +++ b/include/astnodes.h @@ -1689,7 +1689,7 @@ AstPolyCallType* convert_call_to_polycall(AstCall* call); void add_overload_option(bh_arr(OverloadOption)* poverloads, u64 precedence, AstTyped* overload); AstTyped* find_matching_overload_by_arguments(bh_arr(OverloadOption) overloads, Arguments* args); AstTyped* find_matching_overload_by_type(bh_arr(OverloadOption) overloads, Type* type); -void report_unable_to_match_overload(AstCall* call); +void report_unable_to_match_overload(AstCall* call, bh_arr(OverloadOption) overloads); void expand_macro(AstCall** pcall, AstFunction* template); AstFunction* macro_resolve_header(AstMacro* macro, Arguments* args, OnyxToken* callsite, b32 error_if_failed); diff --git a/src/checker.c b/src/checker.c index e99aadf9..5ca6d15e 100644 --- a/src/checker.c +++ b/src/checker.c @@ -534,7 +534,7 @@ static CheckStatus check_resolve_callee(AstCall* call, AstTyped** effective_call &call->args); if (new_callee == NULL) { - report_unable_to_match_overload(call); + report_unable_to_match_overload(call, ((AstOverloadedFunction *) callee)->overloads); return Check_Error; } diff --git a/src/utils.c b/src/utils.c index b7d99036..611ad8de 100644 --- a/src/utils.c +++ b/src/utils.c @@ -483,7 +483,7 @@ AstTyped* find_matching_overload_by_type(bh_arr(OverloadOption) overloads, Type* return matched_overload; } -void report_unable_to_match_overload(AstCall* call) { +void report_unable_to_match_overload(AstCall* call, bh_arr(OverloadOption) overloads) { char* arg_str = bh_alloc(global_scratch_allocator, 1024); arg_str[0] = '\0'; @@ -515,6 +515,20 @@ void report_unable_to_match_overload(AstCall* call) { onyx_report_error(call->token->pos, Error_Critical, "Unable to match overloaded function with provided argument types: (%s)", arg_str); bh_free(global_scratch_allocator, arg_str); + + // CLEANUP SPEED: This currently rebuilds the complete set of overloads every time one is looked up. + // This should be cached in the AstOverloadedFunction or somewhere like that. + bh_imap all_overloads; + bh_imap_init(&all_overloads, global_heap_allocator, bh_arr_length(overloads) * 2); + build_all_overload_options(overloads, &all_overloads); + + i32 i = 1; + bh_arr_each(bh__imap_entry, entry, all_overloads.entries) { + AstTyped* node = (AstTyped *) strip_aliases((AstNode *) entry->key); + onyx_report_error(node->token->pos, Error_Critical, "Here is one of the overloads. %d/%d", i++, bh_arr_length(all_overloads.entries)); + } + + bh_imap_free(&all_overloads); } -- 2.25.1