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 the "not exhaustive" diagnostic in the presence of a when clause. #45157

Closed
gafter opened this issue Jun 14, 2020 · 0 comments · Fixed by #46143
Closed

Improve the "not exhaustive" diagnostic in the presence of a when clause. #45157

gafter opened this issue Jun 14, 2020 · 0 comments · Fixed by #46143
Assignees
Labels
4 - In Review A fix for the issue is submitted for review. Area-Compilers Bug Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings. Feature - Pattern Matching Pattern Matching
Milestone

Comments

@gafter
Copy link
Member

gafter commented Jun 14, 2020

After #44702 we produce a diagnostic that gives an example of a pattern that would cover a non-covered scenario in a switch expression that isn't exhaustive. However, we don't tell the user when that is because of the presence of a when clause. @alrz observed this in code review:

I wonder what example we give for:

return unsigned switch 
{
  0 => true,
  var x when x > 0 => false,
};

I would expect _ since any other number is caught by the second arm. F# gives the example anyways but has a special diagnostic in presence of when. For example, the value '1' may indicate a case not covered by the pattern(s). However, a pattern rule with a 'when' clause might successfully match this value.

We should definitely enhance the diagnostic to include this information when appropriate.

@gafter gafter self-assigned this Jun 14, 2020
@gafter gafter added Area-Compilers Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings. Feature - Pattern Matching Pattern Matching labels Jun 14, 2020
@gafter gafter added this to the Compiler.Net5 milestone Jun 14, 2020
@jaredpar jaredpar added the Bug label Jun 22, 2020
@jaredpar jaredpar modified the milestones: Compiler.Net5, 16.8 Jun 23, 2020
gafter pushed a commit to gafter/roslyn that referenced this issue Jul 20, 2020
@gafter gafter added the 4 - In Review A fix for the issue is submitted for review. label Jul 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 - In Review A fix for the issue is submitted for review. Area-Compilers Bug Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings. Feature - Pattern Matching Pattern Matching
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants