printing out all overloads when #match fails
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 6 May 2022 03:11:37 +0000 (22:11 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 6 May 2022 03:11:37 +0000 (22:11 -0500)
include/astnodes.h
src/checker.c
src/utils.c

index 644acd6d85cd07bd21e75424c0d7956385d73381..b209ce0e764d5452bda6bf6fb220d3b436c9d9e3 100644 (file)
@@ -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);
index e99aadf987cf86272b0f23aa52fdb5eaa0570c87..5ca6d15ecaad207d8fa3fc307579bcbe731277eb 100644 (file)
@@ -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;
         }
 
index b7d99036de97058d6ac770c81cce1db30f938cc4..611ad8de35e49dd9903f3c4f997785570012549b 100644 (file)
@@ -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);
 }