From a6720a7ac527b9e45b1021430256870cd04a5713 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com>
Date: Mon, 12 Apr 2021 09:34:03 +0200
Subject: [PATCH] Fix builtin function call disambiguation

In the case of multiple function candidates, if one was an exact
match, it was incorrectly considered an ambiguous call.
---
 src/language/utils/BuiltinFunctionEmbedderUtils.cpp | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/language/utils/BuiltinFunctionEmbedderUtils.cpp b/src/language/utils/BuiltinFunctionEmbedderUtils.cpp
index 9899fee3e..ffe1112d0 100644
--- a/src/language/utils/BuiltinFunctionEmbedderUtils.cpp
+++ b/src/language/utils/BuiltinFunctionEmbedderUtils.cpp
@@ -233,12 +233,20 @@ getBuiltinFunctionEmbedder(ASTNode& n)
       return callable_id_list[0];
     }
     default: {
+      auto& builtin_function_embedder_table = n.m_symbol_table->builtinFunctionEmbedderTable();
+      for (auto callable_id : callable_id_list) {
+        std::shared_ptr builtin_function_embedder = builtin_function_embedder_table[callable_id];
+        // If has exact match return it
+        if (dataTypeName(args_node.m_data_type) == dataTypeName(builtin_function_embedder->getParameterDataTypes())) {
+          return callable_id;
+        }
+      }
+      // else this is an ambiguous call
       std::ostringstream error_msg;
       error_msg << "ambiguous function call " << rang::fgB::red << builtin_function_name << rang::style::reset
                 << rang::style::bold << ": " << rang::fgB::yellow << dataTypeName(args_node.m_data_type)
                 << rang::style::reset << rang::style::bold << "\nnote: candidates are";
 
-      auto& builtin_function_embedder_table = n.m_symbol_table->builtinFunctionEmbedderTable();
       for (auto callable_id : callable_id_list) {
         std::shared_ptr builtin_function_embedder = builtin_function_embedder_table[callable_id];
 
-- 
GitLab