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

[Suggestion] Allow optional opt-in for requiring null handling case #36

Open
AnthonyIacono opened this issue Nov 29, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@AnthonyIacono
Copy link

Hello!

First of all, I absolutely love this library. I really appreciate your work on it :)

I ran into a case today where I had refactored some code that previously had not allowed null to be a valid value, but now I have switch cases throwing ExhaustiveMatch.Failed. I realized it was because I had not been handling the null case in the switch.

In the documentation, I see you have the following:

Since C# reference types are always nullable, but may be intended to never be null, exhaustiveness checking does not require a case for null. If a null value is expected it can be handled by a case null:. The analyzer will ignore this case for its analysis.

For nullable enum types, the analyzer requires that there be a case null: to handle the null value.

I understand that this might not be desired as a default behavior, but I would really personally like to be forced to handle null on reference types.

Is there any way that we can see this as an opt-in thing in the future? Perhap something we can decorate our assembly with as an attribute, or similar.

Thank you!
Anthony

@WalkerCodeRanger
Copy link
Owner

I think this is a good idea and should probably be implemented in concert with #27 "Support C# 8 Nullable Reference Types" to make sure that it plays well with that.

@WalkerCodeRanger WalkerCodeRanger added the enhancement New feature or request label Aug 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants