diff options
author | Alfredo Di Napoli <alfredo@well-typed.com> | 2021-04-20 11:03:01 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-05-20 18:08:37 -0400 |
commit | aac87bd388547e28aca1c19e7436ff5fa9245f04 (patch) | |
tree | 3c03ec7ad5336d45c4108483df0a2f5bce70de1f /compiler/GHC/Tc | |
parent | 7c066734705048edb5b5b0afc30acea0805ec18d (diff) | |
download | haskell-aac87bd388547e28aca1c19e7436ff5fa9245f04.tar.gz |
Extensible Hints for diagnostic messages
This commit extends the GHC diagnostic hierarchy with a `GhcHint` type,
modelling helpful suggestions emitted by GHC which can be used to deal
with a particular warning or error.
As a direct consequence of this, the `Diagnostic` typeclass has been extended
with a `diagnosticHints` method, which returns a `[GhcHint]`. This means
that now we can clearly separate out the printing of the diagnostic
message with the suggested fixes.
This is done by extending the `printMessages` function in
`GHC.Driver.Errors`.
On top of that, the old `PsHint` type has been superseded by the new `GhcHint`
type, which de-duplicates some hints in favour of a general `SuggestExtension`
constructor that takes a `GHC.LanguageExtensions.Extension`.
Diffstat (limited to 'compiler/GHC/Tc')
-rw-r--r-- | compiler/GHC/Tc/Errors/Ppr.hs | 15 | ||||
-rw-r--r-- | compiler/GHC/Tc/Module.hs | 4 | ||||
-rw-r--r-- | compiler/GHC/Tc/Utils/Monad.hs | 6 |
3 files changed, 20 insertions, 5 deletions
diff --git a/compiler/GHC/Tc/Errors/Ppr.hs b/compiler/GHC/Tc/Errors/Ppr.hs index ffabf0f69c..650befdd8f 100644 --- a/compiler/GHC/Tc/Errors/Ppr.hs +++ b/compiler/GHC/Tc/Errors/Ppr.hs @@ -31,6 +31,7 @@ instance Diagnostic TcRnMessage where -> mkDecorated [ text "The import item" <+> quotes (ppr ie) <+> text "does not have an explicit import list" ] + diagnosticReason = \case TcRnUnknownMessage m -> diagnosticReason m @@ -45,6 +46,20 @@ instance Diagnostic TcRnMessage where TcRnMissingImportList{} -> WarningWithFlag Opt_WarnMissingImportList + diagnosticHints = \case + TcRnUnknownMessage m + -> diagnosticHints m + TcRnImplicitLift{} + -> noHints + TcRnUnusedPatternBinds{} + -> noHints + TcRnDodgyImports{} + -> noHints + TcRnDodgyExports{} + -> noHints + TcRnMissingImportList{} + -> noHints + dodgy_msg :: (Outputable a, Outputable b) => SDoc -> a -> b -> SDoc dodgy_msg kind tc ie = sep [ text "The" <+> kind <+> text "item" diff --git a/compiler/GHC/Tc/Module.hs b/compiler/GHC/Tc/Module.hs index 50b832ed49..450e97819a 100644 --- a/compiler/GHC/Tc/Module.hs +++ b/compiler/GHC/Tc/Module.hs @@ -214,7 +214,7 @@ tcRnModule hsc_env mod_sum save_rn_syntax logger = hsc_logger hsc_env home_unit = hsc_home_unit hsc_env err_msg = mkPlainErrorMsgEnvelope loc $ - TcRnUnknownMessage $ mkPlainError $ + TcRnUnknownMessage $ mkPlainError noHints $ text "Module does not have a RealSrcSpan:" <+> ppr this_mod pair :: (Module, SrcSpan) @@ -3152,5 +3152,5 @@ mark_plugin_unsafe dflags = unless (gopt Opt_PluginTrustworthy dflags) $ singleMessage $ mkPlainMsgEnvelope dflags noSrcSpan $ TcRnUnknownMessage $ - mkPlainDiagnostic WarningWithoutFlag $ + mkPlainDiagnostic WarningWithoutFlag noHints $ Outputable.text unsafeText diff --git a/compiler/GHC/Tc/Utils/Monad.hs b/compiler/GHC/Tc/Utils/Monad.hs index 730e666a2a..2d9298e12b 100644 --- a/compiler/GHC/Tc/Utils/Monad.hs +++ b/compiler/GHC/Tc/Utils/Monad.hs @@ -1038,7 +1038,7 @@ mkLongErrAt loc msg extra let msg' = pprWithUnitState unit_state msg in return $ mkErrorMsgEnvelope loc printer $ TcRnUnknownMessage - $ mkDecoratedError [msg', extra] } + $ mkDecoratedError noHints [msg', extra] } mkTcRnMessage :: DiagnosticReason -> SrcSpan @@ -1058,7 +1058,7 @@ mkTcRnMessage reason loc important context extra in return $ mkMsgEnvelope dflags loc printer $ TcRnUnknownMessage - $ mkDecoratedDiagnostic reason errDocs } + $ mkDecoratedDiagnostic reason noHints errDocs } addLongErrAt :: SrcSpan -> SDoc -> SDoc -> TcRn () addLongErrAt loc msg extra = mkLongErrAt loc msg extra >>= reportDiagnostic @@ -1585,7 +1585,7 @@ add_diagnostic_at reason loc msg extra_info dflags <- getDynFlags ; let { dia = mkMsgEnvelope dflags loc printer $ TcRnUnknownMessage $ - mkDecoratedDiagnostic reason [msg, extra_info] } ; + mkDecoratedDiagnostic reason noHints [msg, extra_info] } ; reportDiagnostic dia } |