From 2189622de08daee89bba4768e73eb5ed156da54d Mon Sep 17 00:00:00 2001 From: ieviev <36763595+ieviev@users.noreply.github.com> Date: Fri, 9 May 2025 22:47:14 +0300 Subject: [PATCH 1/2] Add note about exhaustive enum matching --- docs/fsharp/language-reference/enumerations.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/fsharp/language-reference/enumerations.md b/docs/fsharp/language-reference/enumerations.md index 1c9c17f59977e..484f3bb2f6f8f 100644 --- a/docs/fsharp/language-reference/enumerations.md +++ b/docs/fsharp/language-reference/enumerations.md @@ -44,6 +44,8 @@ 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. + ## See also - [F# Language Reference](index.md) From 1a0e8b622a67f70916f00417ed0daf14b2a6bc92 Mon Sep 17 00:00:00 2001 From: ieviev <36763595+ieviev@users.noreply.github.com> Date: Mon, 12 May 2025 22:15:26 +0300 Subject: [PATCH 2/2] Update docs/fsharp/language-reference/enumerations.md Co-authored-by: Tomas Grosup --- docs/fsharp/language-reference/enumerations.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/fsharp/language-reference/enumerations.md b/docs/fsharp/language-reference/enumerations.md index 484f3bb2f6f8f..68583cce285c3 100644 --- a/docs/fsharp/language-reference/enumerations.md +++ b/docs/fsharp/language-reference/enumerations.md @@ -46,6 +46,8 @@ Additionally, cases for enums are always emitted as `public`. This is so that th 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)