-
Notifications
You must be signed in to change notification settings - Fork 788
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
Pattern discard allowed for union case that takes no data #13851
Comments
It always triggers me that when refactoring a DU my code still still compilers where I’m using _ in pattern matching 😟. An error, warning might help here ? |
Things have changed a bit since 2016, and we now are more inclined to emit new informationals and warnings, protected by a So I'd definitely be ok with emitting at least an informational, and possibly a warning for this case. |
Was this originally missed or was this intended as a source compatibility feature? (being able to drop data in select scenarios) Do informational diags pop up in IDEs? I wouldn't mind a warning tbh. |
It crept in somewhere along the way
Yes they show, but very light decorations |
@edgarfgp great you’re trying to fix that old bug I reported 6yrs back in #1592. Once this is done, we should probably change the docs accordingly, see suggestion here on this issue: dotnet/docs#20858. Btw, if we make this informational (not a warning), surely a langversion switch isn’t necessary? |
@abelbraaksma Thanks for raising this years ago , This was confusing to me while I was learning . So I decided fix it :)
Yeah that is good idea. will update the docs if this gets merged
I thought the same while I was implementing this and IMO a warning (no informational) will be more explicit and will help us remove those unnecessary wildcards. Also, it seems the informational warning is shown, but with very light decorations. |
I agree that warning + language switch is better in making this more visible. |
Agree, I think it should be a warning behind language version. It should also be easy to add a quick fix to VS (and other IDEs) which will be removing unnecessary discards. |
Awesome to see this fixed! |
Match discards aren't type checked against case
The text was updated successfully, but these errors were encountered: