A compiler warning flags source code that remains compilable but may be incomplete, unintended, or discouraged. In pattern matching, it can indicate that an expression does not handle every possible value. Because expressions must return a value, an unmatched runtime case would otherwise raise an exception. section 8.1.1
Pattern-matching warnings provide several practical signals:
- An incomplete-match warning means that one or more possible cases lack a handler. section 8.3.3
- An unreachable-pattern warning means an earlier pattern already catches the value, so the later pattern can never run. section 8.1.1
- Pattern order matters: placing a wildcard first prevents later patterns from being reached. section 8.1.1
Adding a new union case
Suppose ContactMethod initially has three cases and sendTo handles each explicitly. Adding SMS of number:string produces an incomplete-match warning. Adding an SMS handler removes the warning and identifies every other match that needs updating. This makes a union change visible throughout the codebase. section 8.3.3
Treat warnings as design feedback rather than noise. Prefer explicit union cases over a wildcard so future cases cannot be silently absorbed. Where a wildcard is unavoidable, consider an explicit exception that logs the value or return an error value instead. Some teams treat these warnings as errors and reject code with unhandled matches. section 8.1.1 section 14.1.1
warning FS0104: Enums may take values outside known cases. For example, the value 'enum<System.ConsoleModifiers> (0)' may indicate a case not covered by the pattern(s).
Shows a warning for an enum value that may fall outside the known cases, explaining why an apparently complete match may still require a fallback. section 8.1.1

