Skip to content

Add note about exhaustive enum matching #46067

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/fsharp/language-reference/enumerations.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ The default `enum` function works with type `int32`. Therefore, it cannot be use

Additionally, cases for enums are always emitted as `public`. This is so that they align with C# and the rest of the .NET platform.

To enable [exhaustive matching](match-expressions.md) for only the defined enum cases, you can suppress warning FS0104 using the directive `#nowarn "104"`. This allows the compiler to treat only declared enum values as valid during pattern matching, avoiding the need for a catch-all case — useful when you're certain all values are covered.

The warning FS0104 (`Enums may take values outside known cases.`) exists because enums can be assigned arbitrary underlying values, e.g. directly or as a result of [bitwise operations](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/enum#enumeration-types-as-bit-flags)

## See also

- [F# Language Reference](index.md)
Expand Down