Header menu logo F# Compiler Guide


The key types are:

and functions

For the compiler, a key file is https://github.com/dotnet/fsharp/blob/main/src/Compiler/FSComp.txt holding most of the messages. There are also a few other similar files including some old error messages in FSStrings.resx.

Adding Diagnostics

Adding or adjusting diagnostics emitted by the compiler is usually straightforward (though it can sometimes imply deeper compiler work). Here's the general process:

  1. Reproduce the compiler error or warning with the latest F# compiler built from the F# compiler repository.
  2. Find the error code (such as FS0020) in the message.
  3. Use a search tool and search for a part of the message. You should find it in FSComp.fs with a title, such as parsMissingTypeArgs.
  4. Use another search tool or a tool like Find All References / Find Usages to see where it's used in the compiler source code.
  5. Set a breakpoint at the location in source you found. If you debug the compiler with the same steps, it should trigger the breakpoint you set. This verifies that the location you found is the one that emits the error or warning you want to improve.

From here, you can either simply update the error text, or you can use some of the information at the point in the source code you identified to see if there is more information to include in the error message. For example, if the error message doesn't contain information about the identifier the user is using incorrectly, you may be able to include the name of the identifier based on data the compiler has available at that stage of compilation.

If you're including data from user code in an error message, it's important to also write a test that verifies the exact error message for a given string of F# code.

Formatting Typed Tree items in Diagnostics

Diagnostics must often format TAST items as user text. When formatting these, you normally use either

When formatting "info" objects, see the functions in the NicePrint module.

Notes on displaying types

Diagnostics must often format types.


The file FSComp.txt contains the canonical listing of diagnostic messages, but there are also .xlf localization files for various languages. See the DEVGUIDE for more details.

Enabling a warning or error by default

The file CompilerDiagnostics.fs contains the function IsWarningOrInfoEnabled, which determines whether a given diagnostic is emitted.

Type something to start searching.