GHC.Types.Error

ghc-9.2.0.20210422: The GHC API

Safe Haskell | Safe-Inferred
Language | Haskell2010

GHC.Types.Error

Contents

- Messages
- Constructing individual errors
- Queries

Synopsis

- data Messages e
- type WarningMessages = Bag (MsgEnvelope DecoratedSDoc)
- type ErrorMessages = Bag (MsgEnvelope DecoratedSDoc)
- mkMessages :: Bag (MsgEnvelope e) -> Messages e
- emptyMessages :: Messages e
- isEmptyMessages :: Messages e -> Bool
- addMessage :: MsgEnvelope e -> Messages e -> Messages e
- unionMessages :: Messages e -> Messages e -> Messages e
- data MsgEnvelope e = MsgEnvelope {
  - errMsgSpan :: SrcSpan
  - errMsgContext :: PrintUnqualified
  - errMsgDiagnostic :: e
  - errMsgSeverity :: Severity
  - errMsgReason :: WarnReason
  }
- type WarnMsg = MsgEnvelope DecoratedSDoc
- data SDoc
- data DecoratedSDoc
- data Severity
  - = SevOutput
  - | SevFatal
  - | SevInteractive
  - | SevDump
  - | SevInfo
  - | SevWarning
  - | SevError
- class RenderableDiagnostic a where
  - renderDiagnostic :: a -> DecoratedSDoc
- pprMessageBag :: Bag SDoc -> SDoc
- mkDecorated :: [SDoc] -> DecoratedSDoc
- mkLocMessage :: Severity -> SrcSpan -> SDoc -> SDoc
- mkLocMessageAnn :: Maybe String -> Severity -> SrcSpan -> SDoc -> SDoc
- getSeverityColour :: Severity -> Scheme -> PprColour
- getCaretDiagnostic :: Severity -> SrcSpan -> IO SDoc
- makeIntoWarning :: WarnReason -> MsgEnvelope e -> MsgEnvelope e
- mkMsgEnvelope :: SrcSpan -> PrintUnqualified -> SDoc -> MsgEnvelope DecoratedSDoc
- mkPlainMsgEnvelope :: SrcSpan -> SDoc -> MsgEnvelope DecoratedSDoc
- mkErr :: SrcSpan -> PrintUnqualified -> e -> MsgEnvelope e
- mkLongMsgEnvelope :: SrcSpan -> PrintUnqualified -> SDoc -> SDoc -> MsgEnvelope DecoratedSDoc
- mkWarnMsg :: SrcSpan -> PrintUnqualified -> SDoc -> MsgEnvelope DecoratedSDoc
- mkPlainWarnMsg :: SrcSpan -> SDoc -> MsgEnvelope DecoratedSDoc
- mkLongWarnMsg :: SrcSpan -> PrintUnqualified -> SDoc -> SDoc -> MsgEnvelope DecoratedSDoc
- isErrorMessage :: MsgEnvelope e -> Bool
- isWarningMessage :: MsgEnvelope e -> Bool
- getErrorMessages :: Messages e -> Bag (MsgEnvelope e)
- getWarningMessages :: Messages e -> Bag (MsgEnvelope e)
- partitionMessages :: Messages e -> (Bag (MsgEnvelope e), Bag (MsgEnvelope e))
- errorsFound :: Messages e -> Bool

# Messages

data Messages e Source #

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

#### Instances

Instances details

Functor Messages # |
Instance details Defined in GHC.Types.Error Methods fmap :: (a -> b) -> Messages a -> Messages b Source # (<$) :: a -> Messages b -> Messages a Source #

type WarningMessages = Bag (MsgEnvelope DecoratedSDoc) Source #

type ErrorMessages = Bag (MsgEnvelope DecoratedSDoc) Source #

mkMessages :: Bag (MsgEnvelope e) -> Messages e Source #

emptyMessages :: Messages e Source #

isEmptyMessages :: Messages e -> Bool Source #

addMessage :: MsgEnvelope e -> Messages e -> Messages e Source #

unionMessages :: Messages e -> Messages e -> Messages e Source #

Joins two collections of messages together.

data MsgEnvelope e Source #

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, its severity, etc. Finally, multiple `MsgEnvelope`s are aggregated into `Messages` that are returned to the user.

Constructors

MsgEnvelope |
Fields errMsgSpan :: SrcSpan The SrcSpan is used for sorting errors into line-number order errMsgContext :: PrintUnqualified errMsgDiagnostic :: e errMsgSeverity :: Severity errMsgReason :: WarnReason

#### Instances

Instances details

Functor MsgEnvelope # |
Instance details Defined in GHC.Types.Error Methods fmap :: (a -> b) -> MsgEnvelope a -> MsgEnvelope b Source # (<$) :: a -> MsgEnvelope b -> MsgEnvelope a Source #
Show (MsgEnvelope DecoratedSDoc) # |
Instance details Defined in GHC.Types.Error Methods showsPrec :: Int -> MsgEnvelope DecoratedSDoc -> ShowS Source # show :: MsgEnvelope DecoratedSDoc -> String Source # showList :: [MsgEnvelope DecoratedSDoc] -> ShowS Source #

type WarnMsg = MsgEnvelope DecoratedSDoc Source #

data SDoc Source #

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.

#### Instances

Instances details

IsString SDoc # |
Instance details Defined in GHC.Utils.Outputable Methods fromString :: String -> SDoc Source #
Outputable SDoc # |
Instance details Defined in GHC.Utils.Outputable Methods ppr :: SDoc -> SDoc Source #
OutputableP env SDoc # |
Instance details Defined in GHC.Utils.Outputable Methods pdoc :: env -> SDoc -> SDoc Source #

data DecoratedSDoc Source #

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`.

#### Instances

Instances details

RenderableDiagnostic DecoratedSDoc # |
Instance details Defined in GHC.Types.Error Methods renderDiagnostic :: DecoratedSDoc -> DecoratedSDoc Source #
Show (MsgEnvelope DecoratedSDoc) # |
Instance details Defined in GHC.Types.Error Methods showsPrec :: Int -> MsgEnvelope DecoratedSDoc -> ShowS Source # show :: MsgEnvelope DecoratedSDoc -> String Source # showList :: [MsgEnvelope DecoratedSDoc] -> ShowS Source #

data Severity Source #

Constructors

SevOutput |
SevFatal |
SevInteractive |
SevDump | Log message intended for compiler developers No file/line/column stuff
SevInfo | Log messages intended for end users. No file/line/column stuff.
SevWarning |
SevError | SevWarning and SevError are used for warnings and errors o The message has a file/line/column heading, plus "warning:" or "error:", added by mkLocMessags o Output is intended for end users

#### Instances

Instances details

Show Severity # |
Instance details Defined in GHC.Types.Error Methods showsPrec :: Int -> Severity -> ShowS Source # show :: Severity -> String Source # showList :: [Severity] -> ShowS Source #
ToJson Severity # |
Instance details Defined in GHC.Types.Error Methods json :: Severity -> JsonDoc Source #
Eq Severity # |
Instance details Defined in GHC.Types.Error Methods (==) :: Severity -> Severity -> Bool # (/=) :: Severity -> Severity -> Bool #

class RenderableDiagnostic a where Source #

A class for types (typically errors and warnings) which can be "rendered" into an opaque `DecoratedSDoc`. For more information, see Note [Rendering Messages].

Methods

renderDiagnostic :: a -> DecoratedSDoc Source #

#### Instances

Instances details

RenderableDiagnostic DecoratedSDoc # |
Instance details Defined in GHC.Types.Error Methods renderDiagnostic :: DecoratedSDoc -> DecoratedSDoc Source #

pprMessageBag :: Bag SDoc -> SDoc Source #

mkDecorated :: [SDoc] -> DecoratedSDoc Source #

Creates a new `DecoratedSDoc` out of a list of `SDoc`.

mkLocMessage :: Severity -> SrcSpan -> SDoc -> SDoc Source #

Make an unannotated error message with location info.

mkLocMessageAnn Source #

Arguments

:: Maybe String | optional annotation
-> Severity | severity
-> SrcSpan | location
-> SDoc | message
-> SDoc |

Make a possibly annotated error message with location info.

getSeverityColour :: Severity -> Scheme -> PprColour Source #

getCaretDiagnostic :: Severity -> SrcSpan -> IO SDoc Source #

makeIntoWarning :: WarnReason -> MsgEnvelope e -> MsgEnvelope e Source #

# Constructing individual errors

mkMsgEnvelope :: SrcSpan -> PrintUnqualified -> SDoc -> MsgEnvelope DecoratedSDoc Source #

A short (one-line) error message

mkPlainMsgEnvelope :: SrcSpan -> SDoc -> MsgEnvelope DecoratedSDoc Source #

Variant that doesn't care about qualified/unqualified names

mkErr :: SrcSpan -> PrintUnqualified -> e -> MsgEnvelope e Source #

mkLongMsgEnvelope :: SrcSpan -> PrintUnqualified -> SDoc -> SDoc -> MsgEnvelope DecoratedSDoc Source #

A long (multi-line) error message

mkWarnMsg :: SrcSpan -> PrintUnqualified -> SDoc -> MsgEnvelope DecoratedSDoc Source #

A short (one-line) error message

mkPlainWarnMsg :: SrcSpan -> SDoc -> MsgEnvelope DecoratedSDoc Source #

Variant that doesn't care about qualified/unqualified names

mkLongWarnMsg :: SrcSpan -> PrintUnqualified -> SDoc -> SDoc -> MsgEnvelope DecoratedSDoc Source #

A long (multi-line) error message

# Queries

isErrorMessage :: MsgEnvelope e -> Bool Source #

isWarningMessage :: MsgEnvelope e -> Bool Source #

getErrorMessages :: Messages e -> Bag (MsgEnvelope e) Source #

getWarningMessages :: Messages e -> Bag (MsgEnvelope e) Source #

partitionMessages :: Messages e -> (Bag (MsgEnvelope e), Bag (MsgEnvelope e)) Source #

Partitions the `Messages` and returns a tuple which first element are the warnings, and the second the errors.

errorsFound :: Messages e -> Bool Source #