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

Poor diagnostics if function use does not match signature #3516

Open
bbannier opened this issue Dec 19, 2023 · 0 comments
Open

Poor diagnostics if function use does not match signature #3516

bbannier opened this issue Dec 19, 2023 · 0 comments

Comments

@bbannier
Copy link
Contributor

bbannier commented Dec 19, 2023

When calling a function with incorrect arguments the diagnostics we surface to users could be improved. The diagnostics we surface seem to come from different layers in the interpreter (lowest layers reported first), and sometimes the lower layers report rather obscure errors.

function f(x: count) {}

I seem to see the "best" diagnostics when passing an integer instead of a count,

f(-1);
error in count and ./foo.zeek, line 4: over-promotion of arithmetic value (count and -1)
error in ./foo.zeek, line 4 and count: type mismatch (-1 and count)
error in ./foo.zeek, line 4: argument type mismatch in function call (f(-1))

The diagnostics get more obscure if I pass a string (note how the error message never mentions string),

f("abc");
error in count and ./foo.zeek, line 4: arithmetic mixed with non-arithmetic (count and abc)
error in ./foo.zeek, line 4 and count: type mismatch (abc and count)
error in ./foo.zeek, line 4: argument type mismatch in function call (f(abc))

If argument counts don't align the diagnostics are completely weird and unlikely to be useful to users,

f(1, 2);
error in ./foo.zeek, line 4: indexing mismatch (list of count and 1, 2)
error in ./foo.zeek, line 4: argument type mismatch in function call (f(1, 2))

Ideally we would show diagnostics which give users a clear action, e.g., when argument types do not match

type mismatch: expected type 'count' for argument 0 but found 'string'

or if the number of arguments does not match

function 'f` takes 1 argument but 2 arguments were supplied
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant