-
Notifications
You must be signed in to change notification settings - Fork 20
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 matching enums: adjust warning #652
Labels
Milestone
Comments
Just going to say that I like this suggestion as-is. |
Yep, nothing much to say other than 👍 on a more descriptive warning for when we know we're pattern matching over an enum. |
Nothing I can complain about too.
|
Definitely ok |
This one doesn't need an RFC, just submit a PR |
This was referenced Mar 14, 2018
@charlesroddie this can be closed; it's completed and merged |
Thank you! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pattern matching enums: adjust warning
Enums are important for interop with non-F# .Net code. Currently, pattern matching an Enum gives a warning:
I suggest that a different warning be given where:
enum<E>(1)
) that the pattern match would not handle.In this case the warning should be "FS**** Enums may take values outside of known cases." Edit: this is now implemented as FS0104
Current problem
To avoid seeing the FS0025 warning, a user must reduce compile-time safety:
Pros of change
The change will distinguish between incompleteness resulting from the user failing to match all known enums, which is highly likely to lead to runtime failure, and incompleteness resulting from invalid enums, which is much less likely and indicates a problem with other code, not the code that gives the warning.
With the change, to avoid seeing the warning, a user may simply disable the [Edit: FS0104] warning. This will preserve the safety of exhaustive pattern matching. The user will be warned about additions to the enum for example with an FS0025 warning.
This is with the proviso that you are relying on other code not to be using invalid Enums, and that you have the correct enumeration of the enum at compile time. Both of which are reasonable assumptions.
Cons of change
A small amount of extra code would be needed in the pattern match exhaustiveness check.
Extra information
There are people who think there should be a warning. This is why this suggestion is to change the warning rather than eliminate it (which would have been my personal preference).
Estimated cost (XS, S, M, L, XL, XXL):
M
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
The text was updated successfully, but these errors were encountered: