Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error for undefined function in shader #79459

Merged

Conversation

MoltenCoffee
Copy link
Contributor

Problem
Currently, as described in #72120, when an undefined function is called in a shader, an error is shown for the number of arguments, as the for-loop looking for functions did not find any but does following code to continue.

Solution
Adds an error when an undefined function is called in a shader, when the loop does not find the matching function.
Fixes #72120

@MoltenCoffee
Copy link
Contributor Author

MoltenCoffee commented Jul 14, 2023

I just noticed a similar but different warning elsewhere:

_set_error(vformat(RTR("No matching function found for: '%s'."), String(funcname->name)));

This one should actually fire if we return false. An option would be to return false instead of setting an error, as that would trigger behavior that is already defined, but not visbily triggered at the moment.

@bitsawer
Copy link
Member

Indeed, there are a few places that call _validate_function_call() and set the error message differently if it returns false. The logic seems good otherwise, I would maybe keep the exists boolean and simply change the last check to something like this (not tested):

if (exists) {
    if (last_arg_count > args.size()) {
        _set_error(vformat(RTR("Too few arguments for \"%s(%s)\" call. Expected at least %d but received %d."), String(name), arg_list, last_arg_count, args.size()));
    } else if (last_arg_count < args.size()) {
        _set_error(vformat(RTR("Too many arguments for \"%s(%s)\" call. Expected at most %d but received %d."), String(name), arg_list, last_arg_count, args.size()));
    }
}

@MoltenCoffee
Copy link
Contributor Author

That seems like a better solution indeed! Seems to work alright.

@bitsawer
Copy link
Member

You need to fix the code formatting to pass tests, we use clang-format: https://docs.godotengine.org/en/latest/contributing/development/code_style_guidelines.html#using-clang-format-locally (in this case you might be able to fix the style by hand, but using the tool is more reliable).

Also, please squash your commits into a single commit, see https://docs.godotengine.org/en/latest/contributing/workflow/pr_workflow.html#the-interactive-rebase

Copy link
Member

@bitsawer bitsawer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally and it works, looks good to me.

@YuriSizov
Copy link
Contributor

So if I understand correctly, we aren't actually adding a new error message, we already have one. And with this PR we are preventing earlier checks from triggering and showing a less useful message, right?

@MoltenCoffee
Copy link
Contributor Author

So if I understand correctly, we aren't actually adding a new error message, we already have one. And with this PR we are preventing earlier checks from triggering and showing a less useful message, right?

Correct. The PR was created under a different assumption and although it has been updated since, the title hasn't.

@YuriSizov YuriSizov merged commit 372e9ab into godotengine:master Jul 24, 2023
13 checks passed
@YuriSizov
Copy link
Contributor

Thanks! And congrats on your first merged Godot pull request!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants