-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Improve diagnostics for duplicate enum discriminants #97533
Copy link
Copy link
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.Diagnostics: Too much output caused by a single piece of incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.Diagnostics: Too much output caused by a single piece of incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
This is split out from the discussion in #97319.
First, the existing error for duplicate enum discriminants could be improved. The best summary of what we have now can be seen in the test added for #97319, which fixes part of it:
Which outputs:
I suggested that the last version of the error should suggest explicitly stating that the discriminant for
Lastis computed as(Second = -2) + (1 variant later) = -1 = First, or somehow better wording that. Essentially, make it clear to the user that things are incremented positively, regardless of the order of existing discriminants.Secondly, @Bryysen suggested that the code that does this (
check_enum) could definitely use some additional refactoring as well in this comment.