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

Mismatched named arguments could result in a more user-friendly error #5219

Open
wdanilo opened this issue Feb 5, 2023 · 0 comments
Open
Labels
-compiler p-low Low priority x-new-feature Type: new feature request

Comments

@wdanilo
Copy link
Member

wdanilo commented Feb 5, 2023

This task is automatically imported from the old Task Issue Board and it was originally created by Radosław Waśko.
Original issue is here.


To illustrate the issue, run the following program:

from Standard.Base import all

foo arg1=42 arg2=30 =
    arg1+arg2+100

main =
    IO.println foo
    IO.println (foo 10)
    IO.println (foo arg2=44)
    IO.println (foo arg3=45)

It currently produces:

172
140
186
Execution finished with an error: Type error: expected a function, but got 172 (Integer).
        at <enso> mismatch.main<arg-1>(mismatch.enso:10:17-27)
        at <enso> mismatch.main(mismatch.enso:10:5-28)

The error produced is quite unintuitive - in bigger codebases it's much harder to track down what went wrong - why is the method not invokable, I'm calling a function. Of course it makes sense from the point of view of Enso's semantics (if we do not match any named argument, we apply all defaulted ones in the hope that once we call that function, it will return yet another function that may then have an argument that will match; then it returns not a function we were looking for but an Integer which is not invokable).

Still, it could be great if we could improve this error handling to get some more user-friendly message like:

Unexpected_Named_Argument: A named argument `arg3` was provided, but the method does not expect any arguments with that name.

Of course, if I'd do 100 (arg3=10), I should still get Not_Invokable_Error. The new Unexpected_Named_Argument should only apply if I'm calling something callable and there is no match.

Even more ideally, we must know at the callsite what are the possible argument names (this is how we match it against the provided argument name). Thus we could 'browse' these matches and see if any of the arguments have some low edit distance to the provided one (we should set some sane threshold for that, maybe 5 differences? Or depending on the length, 20% of the length diffference?). Then we could suggest similar argument names in the error message (as 90% cases I'm currently getting Not_Invokable_Error is due to typos that would be tremendous help):

Unexpected_Named_Argument: A named argument `arg3` was provided, but the method does not expect any arguments with that name. Did you mean: `arg1`, `arg2`?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-compiler p-low Low priority x-new-feature Type: new feature request
Projects
None yet
Development

No branches or pull requests

1 participant