liveBook · Manning

Warning message

As explained in F# in Action: A Revised Edition of Get Programming with F#

A compiler warning is a diagnostic indicating potentially unintended or discouraged source code that nevertheless remains compilable.

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

How F# in Action: A Revised Edition of Get Programming with F# covers it

How deep it goes
Explains warning causes, pattern ordering, runtime consequences, wildcard tradeoffs, and practical responses.
Examples
Uses overlapping patterns, wildcard matches, enum values, and a newly added SMS discriminated-union case.
What it assumes
Assumes familiarity with pattern matching and discriminated unions while teaching exhaustive handling and wildcard risks through examples.
What you can do after
Diagnose/debug with it by locating missing cases, removing unreachable patterns, and choosing explicit exceptions or error values.
How it connects
Connects compiler warnings with pattern matching, discriminated unions, wildcard patterns, exceptions, and error values.

Also explained in

Compare how 2 books explain warning message →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of F# in Action: A Revised Edition of Get Programming with F#. The section links point to the parts of the book it draws on.