]> git.tdb.fi Git - libs/gl.git/commitdiff
Improve reporting of errors from function resolution
authorMikko Rasa <tdb@tdb.fi>
Thu, 11 Mar 2021 22:23:10 +0000 (00:23 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 11 Mar 2021 22:23:10 +0000 (00:23 +0200)
If there are some overloads, report that none of them matched the
argument types.

source/glsl/validate.cpp

index 1458d01eaaba8743d40e90bb9b030790dca3cad9..8805d41fadf01655f7328b60e501ce8c3a8b73d4 100644 (file)
@@ -2,6 +2,7 @@
 #include <cstring>
 #include <msp/core/raii.h>
 #include <msp/strings/format.h>
+#include <msp/strings/utils.h>
 #include "validate.h"
 
 using namespace std;
@@ -239,7 +240,26 @@ void ReferenceValidator::visit(InterfaceBlockReference &iface)
 void ReferenceValidator::visit(FunctionCall &call)
 {
        if(!call.declaration && !call.constructor)
-               error(call, format("Call to undeclared function '%s'", call.name));
+       {
+               map<string, FunctionDeclaration *>::iterator i = stage->functions.lower_bound(call.name);
+               if(i!=stage->functions.end() && i->second->name==call.name)
+               {
+                       bool valid_types = true;
+                       string signature;
+                       for(NodeArray<Expression>::const_iterator j=call.arguments.begin(); (valid_types && j!=call.arguments.end()); ++j)
+                       {
+                               if((*j)->type)
+                                       append(signature, ", ", (*j)->type->name);
+                               else
+                                       valid_types = false;
+                       }
+
+                       if(valid_types)
+                               error(call, format("No matching overload found for call to '%s(%s)'", call.name, signature));
+               }
+               else
+                       error(call, format("Call to undeclared function '%s'", call.name));
+       }
        TraversingVisitor::visit(call);
 }