summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Peyton Jones <simon.peytonjones@gmail.com>2022-01-22 01:08:34 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-02-04 20:36:20 -0500
commita5c7068cc89e8a398eb9c76089875b981a9d830f (patch)
tree992381363a3994b8b19f07fe69e45411e257f8b8
parent88480e55f14c155516c96e716793c76f305d9303 (diff)
downloadhaskell-a5c7068cc89e8a398eb9c76089875b981a9d830f.tar.gz
Add Outputable instance for Messages
c.f. #20980
-rw-r--r--compiler/GHC/Types/Error.hs13
1 files changed, 11 insertions, 2 deletions
diff --git a/compiler/GHC/Types/Error.hs b/compiler/GHC/Types/Error.hs
index fced578e64..2509c25446 100644
--- a/compiler/GHC/Types/Error.hs
+++ b/compiler/GHC/Types/Error.hs
@@ -131,6 +131,12 @@ isEmptyMessages (Messages msgs) = isEmptyBag msgs
singleMessage :: MsgEnvelope e -> Messages e
singleMessage e = addMessage e emptyMessages
+instance Diagnostic e => Outputable (Messages e) where
+ ppr msgs = braces (vcat (map ppr_one (bagToList (getMessages msgs))))
+ where
+ ppr_one :: MsgEnvelope e -> SDoc
+ ppr_one envelope = pprDiagnostic (errMsgDiagnostic envelope)
+
{- Note [Discarding Messages]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -233,6 +239,10 @@ class Diagnostic a where
diagnosticReason :: a -> DiagnosticReason
diagnosticHints :: a -> [GhcHint]
+pprDiagnostic :: Diagnostic e => e -> SDoc
+pprDiagnostic e = vcat [ ppr (diagnosticReason e)
+ , nest 2 (vcat (unDecorated (diagnosticMessage e))) ]
+
-- | A generic 'Hint' message, to be used with 'DiagnosticMessage'.
data DiagnosticHint = DiagnosticHint !SDoc
@@ -546,7 +556,6 @@ getCaretDiagnostic msg_class (RealSrcSpan span _) =
{- Note [Intrinsic And Extrinsic Failures]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
We distinguish between /intrinsic/ and /extrinsic/ failures. We classify in
the former category those diagnostics which are /essentially/ failures, and
their nature can't be changed. This is the case for 'ErrorWithoutFlag'. We
@@ -556,7 +565,7 @@ settings. It's important to be aware of such logic distinction, because when
we are inside the typechecker or the desugarer, we are interested about
intrinsic errors, and to bail out as soon as we find one of them. Conversely,
if we find an /extrinsic/ one, for example because a particular 'WarningFlag'
-makes a warning and error, we /don't/ want to bail out, that's still not the
+makes a warning into an error, we /don't/ want to bail out, that's still not the
right time to do so: Rather, we want to first collect all the diagnostics, and
later classify and report them appropriately (in the driver).
-}