glsl: report no function instead of empty candidate list

When generating the error message for a missing function error where
all available overloads were missing due to a too low GLSL version, we
used to report something like this:

---8<---
0:224(14): error: no matching function for call to
           `textureCubeLod(samplerCube, vec3, float)'; candidates are:
0:224(14): error: type mismatch
---8<---

This is a pretty confusing error message, and can throw people off when
debugging. So let's instead check if any overload is available before we
decide what to print. This allow us to report something like this
instead:

---8<---
0:224(14): error: no function with name 'textureCubeLod'
0:224(14): error: type mismatch
---8<---

This is arguably easier to understand for programmers, and doesn't send
you on a wild goose chase to figure out what argument is wrong just
because you stopped reading the message prematurely. I'm of course
referring to a friend, not me. For sure. I would never do that.

Signed-off-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
This commit is contained in:
Erik Faye-Lund 2019-06-13 12:03:27 +02:00
parent 7e1fe81f56
commit c5f1432296
1 changed files with 17 additions and 2 deletions

View File

@ -748,6 +748,21 @@ generate_array_index(void *mem_ctx, exec_list *instructions,
}
}
static bool
function_exists(_mesa_glsl_parse_state *state,
struct glsl_symbol_table *symbols, const char *name)
{
ir_function *f = symbols->get_function(name);
if (f != NULL) {
foreach_in_list(ir_function_signature, sig, &f->signatures) {
if (sig->is_builtin() && !sig->is_builtin_available(state))
continue;
return true;
}
}
return false;
}
static void
print_function_prototypes(_mesa_glsl_parse_state *state, YYLTYPE *loc,
ir_function *f)
@ -778,9 +793,9 @@ no_matching_function_error(const char *name,
{
gl_shader *sh = _mesa_glsl_get_builtin_function_shader();
if (state->symbols->get_function(name) == NULL
if (!function_exists(state, state->symbols, name)
&& (!state->uses_builtin_functions
|| sh->symbols->get_function(name) == NULL)) {
|| !function_exists(state, sh->symbols, name))) {
_mesa_glsl_error(loc, state, "no function with name '%s'", name);
} else {
char *str = prototype_string(NULL, name, actual_parameters);