summaryrefslogtreecommitdiff
path: root/compiler/GHC/Tc
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2023-04-19 10:04:03 +0100
committerMatthew Pickering <matthewtpickering@gmail.com>2023-05-12 08:58:40 +0100
commitbf113d74d7da6cedc897ebb5536e1f162cd7c4e1 (patch)
treed79c9b5068433844b4b6ef44b98cc2c09edcf480 /compiler/GHC/Tc
parentd68100b847720cbfe0e8923681862373857f63fc (diff)
downloadhaskell-wip/t22884.tar.gz
error messages: Don't display ghci specific hints for missing packageswip/t22884
Tickets like #22884 suggest that it is confusing that GHC used on the command line can suggest options which only work in GHCi. This ticket uses the error message infrastructure to override certain error messages which displayed GHCi specific information so that this information is only showed when using GHCi. The main annoyance is that we mostly want to display errors in the same way as before, but with some additional information. This means that the error rendering code has to be exported from the Iface/Errors/Ppr.hs module. I am unsure about whether the approach taken here is the best or most maintainable solution. Fixes #22884
Diffstat (limited to 'compiler/GHC/Tc')
-rw-r--r--compiler/GHC/Tc/Errors/Ppr.hs20
1 files changed, 14 insertions, 6 deletions
diff --git a/compiler/GHC/Tc/Errors/Ppr.hs b/compiler/GHC/Tc/Errors/Ppr.hs
index 454d179c4b..460301273f 100644
--- a/compiler/GHC/Tc/Errors/Ppr.hs
+++ b/compiler/GHC/Tc/Errors/Ppr.hs
@@ -21,6 +21,10 @@ module GHC.Tc.Errors.Ppr
, inHsDocContext
, TcRnMessageOpts(..)
, pprTyThingUsedWrong
+
+ -- | Useful when overriding message printing.
+ , messageWithInfoDiagnosticMessage
+ , messageWithHsDocContext
)
where
@@ -126,12 +130,8 @@ instance Diagnostic TcRnMessage where
(tcOptsShowContext opts)
(diagnosticMessage opts msg)
TcRnWithHsDocContext ctxt msg
- -> if tcOptsShowContext opts
- then main_msg `unionDecoratedSDoc` ctxt_msg
- else main_msg
- where
- main_msg = diagnosticMessage opts msg
- ctxt_msg = mkSimpleDecorated (inHsDocContext ctxt)
+ -> messageWithHsDocContext opts ctxt (diagnosticMessage opts msg)
+
TcRnSolverReport msg _ _
-> mkSimpleDecorated $ pprSolverReportWithCtxt msg
TcRnRedundantConstraints redundants (info, show_info)
@@ -3259,6 +3259,14 @@ messageWithInfoDiagnosticMessage unit_state ErrInfo{..} show_ctxt important =
in (mapDecoratedSDoc (pprWithUnitState unit_state) important) `unionDecoratedSDoc`
mkDecorated err_info'
+messageWithHsDocContext :: TcRnMessageOpts -> HsDocContext -> DecoratedSDoc -> DecoratedSDoc
+messageWithHsDocContext opts ctxt main_msg = do
+ if tcOptsShowContext opts
+ then main_msg `unionDecoratedSDoc` ctxt_msg
+ else main_msg
+ where
+ ctxt_msg = mkSimpleDecorated (inHsDocContext ctxt)
+
dodgy_msg :: Outputable ie => SDoc -> GlobalRdrElt -> ie -> SDoc
dodgy_msg kind tc ie
= vcat [ text "The" <+> kind <+> text "item" <+> quotes (ppr ie) <+> text "suggests that"