dmd icon indicating copy to clipboard operation
dmd copied to clipboard

Store location of function argument that doesn't match to display `^` at the right index when using `-verrors=context`

Open ryuukk opened this issue 2 years ago • 9 comments

This is an improvement over my previous draft: https://github.com/dlang/dmd/pull/15510

Turns out the functionality was already there through: -verrors=context, however, it didn't display the ^ at the right index, making it not useful

Example:

void test(int a, int b, string c, float d) {}

void testme()
{
    test(1, 1,                 1, 1.0);
}

Before:

x\x\app.d(53): Error: function `app.test(int a, int b, string c, float d)` is not callable using argument types `(int, int, int, double)`                                                                                             
    test(1, 1,                 1, 1.0);                                                                                                                                                                                                         
        ^                                                                                                                                                                                                                                       
x\x\app.d(53):        cannot pass argument `1` of type `int` to parameter `string c`                   

After:

x\x\app.d(53): Error: function `app.test(int a, int b, string c, float d)` is not callable using argument types `(int, int, int, double)`                                                                                             
    test(1, 1,                 1, 1.0);                                                                                                                                                                                                         
                               ^                                                                                                                                                                                                                
x\x\app.d(53):        cannot pass argument `1` of type `int` to parameter `string c`     

This is better UX for debug messages, i'd personally make -verrors=context the default, it's very good

ryuukk avatar Aug 09 '23 21:08 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#15524"

dlang-bot avatar Aug 09 '23 21:08 dlang-bot

Is there a way to display multiple lines?

Eg:

void test(int a, int b, string c, float d) {}

void testme()
{
    test(1, 1,                 
        1, 1.0);
}
x\x\app.d(54): Error: function `app.test(int a, int b, string c, float d)` is not callable using argument types `(int, int, int, double)`                                                                                             
        1, 1.0);                                                                                                                                                                                                                                
        ^                                                                                                                                                                                                                                       
x\x\app.d(54):        cannot pass argument `1` of type `int` to parameter `string c`      

It still is pretty useful, but i'd personally prefer if it could display the whole function, to get a better context, maybe i could add a new error function that accept 2 Locs? (begin and end)

ryuukk avatar Aug 09 '23 22:08 ryuukk

maybe i could add a new error function that accept 2 Locs? (begin and end)

I'd start by getting the correct location working and perhaps do this in a next PR.

dkorpel avatar Aug 09 '23 22:08 dkorpel

Does anyone know why every checks failed? This PR shouldn't affect the tests..

ryuukk avatar Aug 10 '23 03:08 ryuukk

There's a segfault when compiling Phobos.

dkorpel avatar Aug 10 '23 13:08 dkorpel

Also don't forget to add argLoc to the ddoc comment of callMatch

dkorpel avatar Aug 10 '23 14:08 dkorpel

Thanks! I sent a commit with the requested changes

ryuukk avatar Aug 10 '23 15:08 ryuukk

It's green now, so it only still needs a test. You can probably just add REQUIRED_ARGS: -vcolumns or -verrors=context to an existing test for this error and run with AUTO_UPDATE=1. Do you want help with it?

dkorpel avatar Aug 11 '23 09:08 dkorpel

@ryuukk This PR requires a rebase and a test and we are good to go.

RazvanN7 avatar Jan 10 '24 14:01 RazvanN7