Skip to content

Commit 278b13f

Browse files
ievievT-Gro
andauthored
Add note about exhaustive enum matching (#46067)
* Add note about exhaustive enum matching * Update docs/fsharp/language-reference/enumerations.md Co-authored-by: Tomas Grosup <tomasgrosup@microsoft.com> --------- Co-authored-by: Tomas Grosup <tomasgrosup@microsoft.com>
1 parent 48fe102 commit 278b13f

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

docs/fsharp/language-reference/enumerations.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ The default `enum` function works with type `int32`. Therefore, it cannot be use
4444

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

47+
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.
48+
49+
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)
50+
4751
## See also
4852

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

0 commit comments

Comments
 (0)