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
Providing wrong arity to built-ins should explain actual problem #4054
Comments
Hmm this is interesting:
seems like it's mostly a matter of returning the proper error. I'll look into this, seems like a good UX improvement to me. |
We've got multiple stages in the compiler, and the type checker runs after the safety check. Since the safety check fails, that's the error we get. However, there's also an "undefined function" check, and I think it's OK to amend that one: after all, wrong arity means wrong function. |
Thanks for looking into this @srenatus! Yeah, while it might seem pedantic, having clear error messages might be one of the most important investments in the debugging experience IMHO.. so I think it's time well spent :) |
Before, the "undefined function" check stage in the compiler (and query compiler) only asserted that the function was known. Now, we'll also check that the number of arguments _could be_ valid. If it really is valid will be determined by the type checker at a later stage. However, asserting the arity early allows us to give more on-the-spot error messages. Fixes open-policy-agent#4054. Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
* ast/compile: check arity in undefined function stage Before, the "undefined function" check stage in the compiler (and query compiler) only asserted that the function was known. Now, we'll also check that the number of arguments _could be_ valid. If it really is valid will be determined by the type checker at a later stage. However, asserting the arity early allows us to give more on-the-spot error messages. Fixes #4054. Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
Short description
When providing too few arguments to a built-in function, a message about expression or variable being "unsafe" is returned. This doesn't really convey the real problem, which is of course that too few arguments were provided.
Steps To Reproduce
Expected behavior
Output to be something like "
built-in X: expected <string, string, number>, got <string>
"The text was updated successfully, but these errors were encountered: