dmd icon indicating copy to clipboard operation
dmd copied to clipboard

Improve error message for when we pass wrong arguments to a function

Open ryuukk opened this issue 2 years ago • 10 comments

I think it looks better!

Code_UCCb5oZ3kx

Code_d9qARJAbdE

ryuukk avatar Nov 28 '21 00:11 ryuukk

Thanks for your pull request and interest in making D better, @ryuukk! We are looking forward to reviewing it, and you should be hearing from a maintainer soon. Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#13366"

dlang-bot avatar Nov 28 '21 00:11 dlang-bot

You need to change the tests that are making this fail accordingly.

i'll look into it, thanks

  1. Can we really not have one error == one line here?

It wasn't really readable before as a one line

  1. Avoid mixing tabs and spaces.

I'll fix that

  1. Do we use %*s as a format specifier in other errors? (Meaning, has it been vetted as a portable format to use).

I have no idea..

ryuukk avatar Nov 29 '21 15:11 ryuukk

You need to change the tests that are making this fail accordingly.

i'll look into it, thanks

You can use AUTO_UPDATE=1 ./run.d fail, see: https://github.com/dlang/dmd/tree/master/test#quick-guide

dkorpel avatar Nov 29 '21 15:11 dkorpel

  1. Can we really not have one error == one line here?

It wasn't really readable before as a one line

I mean, you can break up an error into multiple lines using errorSupplemental for subsequent messages.

ibuclaw avatar Nov 29 '21 18:11 ibuclaw

Awesome that you're looking into improving diagnostic!

Could we somehow utilize alignment to make it easier to spot which parameter (index) that is fed the wrong parameter?

nordlow avatar Dec 05 '21 07:12 nordlow

I have another request which might belong in a separate PR, namely:

The code snippet

    void f(T)(int x) {}
    unittest { f(42); }

currently erroring as

    template `missing_template_param.f` cannot deduce function from argument types `!()(int)`
    Candidate is: `f(T)(int x)`

could also include a errorSupplemental like

    Candidate `f(T)(int x)` is missing a/its/its (single)/(the first) template parameter `T`

.

nordlow avatar Dec 05 '21 07:12 nordlow

You need to change the tests that are making this fail accordingly.

i'll look into it, thanks

You can use AUTO_UPDATE=1 ./run.d fail, see: https://github.com/dlang/dmd/tree/master/test#quick-guide

thanks!

  1. Can we really not have one error == one line here?

It wasn't really readable before as a one line

I mean, you can break up an error into multiple lines using errorSupplemental for subsequent messages.

i will do that!

@nordlow

that was initially the goal, to put arrows to display wich one is the problem, or maybe put some color, but i'm not familiar with the code base and i got distracted by my wasm project, that's something definitely worth trying, i will try to find some time and finish this little side project of mine!

ryuukk avatar Dec 07 '21 14:12 ryuukk

@ryuukk any progress on this?

RazvanN7 avatar Dec 16 '21 12:12 RazvanN7

@RazvanN7 i am still busy working on my WASM project, also some people raised some interesting point on IRC that i need to take into consideration

So i want to improve it further

ryuukk avatar Dec 16 '21 14:12 ryuukk

%*s

%*s is specified in c89. It is not used as such elsewhere in dmd, but %.*s is used; so the feature is still required.

moon-chilled avatar Dec 16 '21 17:12 moon-chilled