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

Improve error supplemental #16755

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ljmf00
Copy link
Member

@ljmf00 ljmf00 commented Jul 26, 2024

No description provided.

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @ljmf00!

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#16755"

@ljmf00 ljmf00 force-pushed the improve-error-supplemental branch from 774d8ce to b84323a Compare July 29, 2024 10:30
@ljmf00 ljmf00 marked this pull request as ready for review July 29, 2024 10:31
@ljmf00
Copy link
Member Author

ljmf00 commented Jul 29, 2024

Can we agree on a format first before I change every expcted failure test messages? Do you think these messages are ok? CC @dkorpel @JohanEngelen

---
*/

#line 100
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: we could make a pre pass of the testsuite where it instruments the code to add correct line numbers, so the initial comment doesn't affect it,

or:

Start enforcing a #line directive to most of the tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to do away with #line directives since they make it hard to locate the line the error belongs to. Instead, I'm working on implementing this: #14515

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment on #14515 .

@dkorpel
Copy link
Contributor

dkorpel commented Jul 29, 2024

I like the recent addition of supplemental error messages pointing to the declaration site of types / functions related to the error, so adding it to templates looks good to me. If I understand correctly, it just shows the first template declaration, not the 'closest' matching template, but that's a future enhancement.

I don't understand the "instantiated from here: Foo!int" supplemental error though, doesn't it always point to the same location as the initial error?

@ljmf00-wekaio
Copy link

ljmf00-wekaio commented Jul 29, 2024

I like the recent addition of supplemental error messages pointing to the declaration site of types / functions related to the error, so adding it to templates looks good to me. If I understand correctly, it just shows the first template declaration, not the 'closest' matching template, but that's a future enhancement.

I don't understand the "instantiated from here: Foo!int" supplemental error though, doesn't it always point to the same location as the initial error?

The first one does, but the instantiated from here: Foo!int`` is part of the instance stack print (the helper function printInstantiationTrace), when it has more than one in the chain it gives you another `instantiated from here` until the root instantiation. This is similar to other template instance errors that uses this.

Maybe an alternative. Instead of this:

fail_compilation/constraints_aggr.d(109): Error: template instance `imports.constraints.S!int` does not match template declaration `S(T)`
  with `T = int`
  must satisfy the following constraint:
`       N!T`
fail_compilation/constraints_aggr.d(109):        instantiated from here: `S!int`
fail_compilation/imports/constraints.d(67):        Candidate match: S(T) if (N!T)

We could do this, perhaps (notice the difference on line numbers):

fail_compilation/constraints_aggr.d(67): Error: template instance `imports.constraints.S!int` does not match template declaration `S(T)`
  with `T = int`
  must satisfy the following constraint:
`       N!T`
fail_compilation/constraints_aggr.d(109):        instantiated from here: `S!int`

Maybe rewrite the main error message but I'm out of ideas other than swapping it:

fail_compilation/constraints_aggr.d(67): Error: template declaration `S(T)` does not match template instance `imports.constraints.S!int`

@ljmf00-wekaio
Copy link

I like the recent addition of supplemental error messages pointing to the declaration site of types / functions related to the error, so adding it to templates looks good to me. If I understand correctly, it just shows the first template declaration, not the 'closest' matching template, but that's a future enhancement.

It should show up on the multi candidate error message. Maybe I'm missing what you meant. Can you elaborate?

@ljmf00
Copy link
Member Author

ljmf00 commented Aug 1, 2024

Ping @dkorpel

@dkorpel
Copy link
Contributor

dkorpel commented Aug 1, 2024

I mean when there's multiple template overloads, which candidate(s) does it print? My impression was it just picks one, but I didn't study it closely yet.

@ibuclaw
Copy link
Member

ibuclaw commented Aug 2, 2024

I don't see any tests that use -vcontext - can at least one test be added so that the effect on this diagnostic switch can also be seen/checked?

@ljmf00-wekaio
Copy link

I mean when there's multiple template overloads, which candidate(s) does it print? My impression was it just picks one, but I didn't study it closely yet.

See this test example:

fail_compilation/fail134.d(105): Error: template instance `foo!(f)` does not match template declaration `foo(T)`
fail_compilation/fail134.d(105):        instantiated from here: `foo!(f)`
fail_compilation/fail134.d(106):        instantiated from here: `bar!(f)`
fail_compilation/fail134.d(104):        Candidate match: foo(T)
fail_compilation/fail134.d(105):        `f` is not a type

@dkorpel
Copy link
Contributor

dkorpel commented Aug 6, 2024

There's still just one template overload there. What I'm wondering about is this:

void foo(int n : 0) {}
void foo(int n : 1) {}
void foo(int n : 2) {}

alias foo3 = foo!3;

But I noticed that it already prints all candidates in that case:

onlineapp.d(6): Error: template instance `foo!3` does not match any template declaration
onlineapp.d(6):        Candidates are:
onlineapp.d(2):        foo(int n : 0)()
onlineapp.d(3):        foo(int n : 1)()
onlineapp.d(4):        foo(int n : 2)()

The error this PR improves is when it already found a template it must match, but there's an error in the template body. If that's correct, then I think the error should simply say: "Template declared here:", because "Candidate match: " suggests that it prints only one of multiple candidates.

@ljmf00-wekaio
Copy link

There's still just one template overload there. What I'm wondering about is this:

void foo(int n : 0) {}
void foo(int n : 1) {}
void foo(int n : 2) {}

alias foo3 = foo!3;

But I noticed that it already prints all candidates in that case:

onlineapp.d(6): Error: template instance `foo!3` does not match any template declaration
onlineapp.d(6):        Candidates are:
onlineapp.d(2):        foo(int n : 0)()
onlineapp.d(3):        foo(int n : 1)()
onlineapp.d(4):        foo(int n : 2)()

The error this PR improves is when it already found a template it must match, but there's an error in the template body. If that's correct, then I think the error should simply say: "Template declared here:", because "Candidate match: " suggests that it prints only one of multiple candidates.

ok, makes sense, will change to Template declared here:.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants