The key types are:
warning- emit a warning
errorR- emit an error and continue
error- emit an error and throw an exception
errorRecovery- recover from an exception
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
Adding or adjusting diagnostics emitted by the compiler is usually straightforward (though it can sometimes imply deeper compiler work). Here's the general process:
FS0020) in the message.
FSComp.fswith a title, such as
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.
Diagnostics must often format TAST items as user text. When formatting these, you normally use either
The functions in the
NicePrint module such as
NicePrint.outputTyconRef. These take a
DisplayEnv that records the context in which a type was referenced, for example, the open namespaces. Opened namespaces are not shown in the displayed output.
DisplayName properties on the relevant object. This drops the
'n text that .NET adds to the compiled name of a type, and uses the F#-facing name for a type rather than the compiled name for a type (for example, the name given in a
When formatting "info" objects, see the functions in the
Diagnostics must often format types.
When displaying a type, you will normally want to "prettify" the type first. This converts any remaining type inference variables to new, better user-friendly type variables with names like
'a. Various functions prettify types prior to display, for example,
NicePrint.layoutPrettifiedTypes and others.
When displaying multiple types in a comparative way, for example, two types that didn't match, you will want to display the minimal amount of infomation to convey the fact that the two types are different, for example,
When displaying a type, you have the option of displaying the constraints implied by any type variables mentioned in the types, appended as
when .... For example,
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.
CompilerDiagnostics.fs contains the function
IsWarningOrInfoEnabled, which determines whether a given diagnostic is emitted.