HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

  • Packageghc-9.10.3
  • Exports62
  • LanguageGHC2021
  • LicenceBSD-3-Clause
  • SourceError.hs

Messages

11 declarations
newtypenewtype Messages e
#

A collection of messages emitted by GHC during error reporting. A diagnostic message is typically a warning or an error. See Note [Messages].

INVARIANT: All the messages in this collection must be relevant, i.e. their Severity should not be SevIgnore. The smart constructor mkMessages will filter out any message which Severity is SevIgnore.

Instances7Functor, Foldable, Traversable, Semigroup, Monoid, Outputable, …
datadata MsgEnvelope e
#

An envelope for GHC's facts about a running program, parameterised over the domain-specific (i.e. parsing, typecheck-renaming, etc) diagnostics.

To say things differently, GHC emits diagnostics about the running program, each of which is wrapped into a MsgEnvelope that carries specific information like where the error happened, etc. Finally, multiple MsgEnvelopes are aggregated into Messages that are returned to the user.

Constructors

Instances5Functor, Foldable, Traversable, Show, ToJson

Classifying Messages

20 declarations
datadata MessageClass
#

The class for a diagnostic message. The main purpose is to classify a message within GHC, to distinguish it from a debug/dump message vs a proper diagnostic, for which we include a DiagnosticReason.

Constructors

  • MCOutput
  • MCFatal
  • MCInteractive
  • MCDump

    Log message intended for compiler developers No file/line/column stuff

  • MCInfo

    Log messages intended for end users. No file/line/column stuff.

  • MCDiagnostic Severity ResolvedDiagnosticReason (Maybe DiagnosticCode)

    Diagnostics from the compiler. This constructor is very powerful as it allows the construction of a MessageClass with a completely arbitrary permutation of Severity and DiagnosticReason. As such, users are encouraged to use the mkMCDiagnostic smart constructor instead. Use this constructor directly only if you need to construct and manipulate diagnostic messages directly, for example inside GHC.Utils.Error. In all the other circumstances, especially when emitting compiler diagnostics, use the smart constructor.

    The Maybe DiagnosticCode field carries a code (if available) for this diagnostic. If you are creating a message not tied to any error-message type, then use Nothing. In the long run, this really should always have a DiagnosticCode. See Note [Diagnostic codes].

Instances1ToJson
datadata Severity
#

Used to describe warnings and errors o The message has a file/line/column heading, plus "warning:" or "error:", added by mkLocMessage o With SevIgnore the message is suppressed o Output is intended for end users

Constructors

  • SevIgnore

    Ignore this message, for example in case of suppression of warnings users don't want to see. See Note [Suppressing Messages]

  • SevWarning
  • SevError
Instances5Eq, Ord, Show, Outputable, ToJson
classclass HasDefaultDiagnosticOpts (DiagnosticOpts a) => Diagnostic a where
#

A class identifying a diagnostic. Dictionary.com defines a diagnostic as:

"a message output by a computer diagnosing an error in a computer program, computer system, or component device".

A Diagnostic carries the actual description of the message (which, in GHC's case, it can be an error or a warning) and the reason why such message was generated in the first place.

Associated types

  • type family DiagnosticOpts a

    Type of configuration options for the diagnostic.

Methods

Instances8Diagnostic, …
datadata UnknownDiagnostic opts where
#

An existential wrapper around an unknown diagnostic.

Constructors

Instances4ConstructorCodes, ConstructorCode, Diagnostic, DiagnosticOpts
datadata DiagnosticMessage
#

A generic Diagnostic message, without any further classification or provenance: By looking at a DiagnosticMessage we don't know neither where it was generated nor how to interpret its payload (as it's just a structured document). All we can do is to print it out and look at its DiagnosticReason.

Instances3Diagnostic, Show, DiagnosticOpts
datadata DiagnosticReason
#

The reason why a Diagnostic was emitted in the first place. Diagnostic messages are born within GHC with a very precise reason, which can be completely statically-computed (i.e. this is an error or a warning no matter what), or influenced by the specific state of the DynFlags at the moment of the creation of a new Diagnostic. For example, a parsing error is always going to be an error, whereas a 'WarningWithoutFlag Opt_WarnUnusedImports' might turn into an error due to '-Werror' or '-Werror=warn-unused-imports'. Interpreting a DiagnosticReason together with its associated Severity gives us the full picture.

Constructors

Instances3Eq, Show, Outputable
classclass HasDefaultDiagnosticOpts opts where
#

Methods

Instances5HasDefaultDiagnosticOpts

Hints and refactoring actions

11 declarations
datadata GhcHint
#

A type for hints emitted by GHC. A hint suggests a possible way to deal with a particular warning or error.

Constructors

Instances1Outputable

Constructors

  • SuggestSingleExtension !SDoc !Extension

    Suggest to enable the input extension. This is the hint that GHC emits if this is not a "known" fix, i.e. this is GHC giving its best guess on what extension might be necessary to make a certain program compile. For example, GHC might suggests to enable BlockArguments when the user simply formatted incorrectly the input program, so GHC here is trying to be as helpful as possible. If the input SDoc is not empty, it will contain some extra information about the why the extension is required, but it's totally irrelevant/redundant for IDEs and other tools.

  • SuggestAnyExtension !SDoc [Extension]

    Suggest to enable the input extensions. The list is to be intended as disjunctive i.e. the user is suggested to enable any of the extensions listed. If the input SDoc is not empty, it will contain some extra information about the why the extensions are required, but it's totally irrelevant/redundant for IDEs and other tools.

  • SuggestExtensions !SDoc [Extension]

    Suggest to enable the input extensions. The list is to be intended as conjunctive i.e. the user is suggested to enable all the extensions listed. If the input SDoc is not empty, it will contain some extra information about the why the extensions are required, but it's totally irrelevant/redundant for IDEs and other tools.

  • SuggestExtensionInOrderTo !SDoc !Extension

    Suggest to enable the input extension in order to fix a certain problem. This is the suggestion that GHC emits when is more-or-less clear "what's going on". For example, if both DeriveAnyClass and GeneralizedNewtypeDeriving are turned on, the right thing to do is to enabled DerivingStrategies, so in contrast to SuggestSingleExtension GHC will be a bit more "imperative" (i.e. "Use X Y Z in order to ... "). If the input SDoc is not empty, it will contain some extra information about the why the extensions are required, but it's totally irrelevant/redundant for IDEs and other tools.

valuenoHints :: [GhcHint]
#

Helper function to use when no hints can be provided. Currently this function can be used to construct plain DiagnosticMessage and add hints to them, but once #18516 will be fully executed, the main usage of this function would be in the implementation of the diagnosticHints typeclass method, to report the fact that a particular Diagnostic has no hints.

Rendering Messages

11 declarations
newtypenewtype SDoc
#

Represents a pretty-printable document.

To display an SDoc, use printSDoc, printSDocLn, bufLeftRenderSDoc, or renderWithContext. Avoid calling runSDoc directly as it breaks the abstraction layer.

Instances8IsString, Outputable, IsLine, IsDoc, IsOutput, JsRender, …
newtypenewtype DecoratedSDoc
#

A DecoratedSDoc is isomorphic to a '[SDoc]' but it carries the invariant that the input '[SDoc]' needs to be rendered decorated into its final form, where the typical case would be adding bullets between each elements of the list. The type of decoration depends on the formatting function used, but in practice GHC uses the formatBulleted.

Queries

8 declarations

Diagnostic codes

1 declaration
datadata DiagnosticCode
#

A diagnostic code is a namespaced numeric identifier unique to the given diagnostic (error or warning).

All diagnostic codes defined within GHC are given the GHC namespace.

See Note [Diagnostic codes] in GHC.Types.Error.Codes.

Constructors

Instances5Eq, Ord, Show, Outputable, ToJson